Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Am I using the right tool?

Subject: Am I using the right tool?

From: SEJ080003 student

Date: 25 Oct, 2011 02:14:30

Message: 1 of 8

Hi I'm new here. I only has less than a year experience in MATLAB. I
am doing self-learning.. I need your opinion and suggestion in this
matter.

Let say, in the program I want to create, I have a first particle to
be released in a region and it will move randomly inside that region.
Once it meets at certain condition, I would like to release a second
particle into the same region and moves randomly as well. These 2
particles only stop moving and occupy an empty place when they meet
another condition. If they don't, they will keep on moving randomly
until they do. So now we have two particles moving at the same time.
It is as if there are two different loop running at the same time. To
me it seems like running two different things in a program. Is it
possible to have that running in MATLAB? What do you think?

If it is possible, does anyone have any rough ideas on it? I was
thinking on nested loop but what if there are 3 and more? That will be
very confusing.

If not possible, do you have any suggestion on which tool/program that
is suitable for running multiple things at a time?

I have no luck in other forum. I hope I will get response here. I
would really appreciate it very much.

Thank you,
Ain

Subject: Am I using the right tool?

From: ImageAnalyst

Date: 25 Oct, 2011 02:26:36

Message: 2 of 8

Shouldn't be too hard. A year is a long time. I was pretty
proficient with MATLAB after a few days and certainly after a couple
of weeks or a month I could have written this kind of program. It
looks like a "game of life" or automaton kind of program. First
create a big matrix to hold your particles. Then have a "for" loop.
Inside the loop get random numbers using rand() as needed and set the
new positions. Use "if" statements to check for various conditions
that cause new actions such as detecting particle collisions that
would "stop" a particle from moving, or deciding when to release
another particle into the array.

Subject: Am I using the right tool?

From: SEJ080003 student

Date: 25 Oct, 2011 04:17:29

Message: 3 of 8

On Oct 25, 10:26 am, ImageAnalyst <imageanal...@mailinator.com> wrote:
> Shouldn't be too hard.  A year is a long time.  I was pretty
> proficient with MATLAB after a few days and certainly after a couple
> of weeks or a month I could have written this kind of program.  It
> looks like a "game of life" or automaton kind of program.  First
> create a big matrix to hold your particles.  Then have a "for" loop.
> Inside the loop get random numbers using rand() as needed and set the
> new positions.  Use "if" statements to check for various conditions
> that cause new actions such as detecting particle collisions that
> would "stop" a particle from moving, or deciding when to release
> another particle into the array.

Really?? WOW. Do you have any specific method learning it? I use
tutorials but I don't feel like progressing. Right now I'm trying to
alter a code I found on the internet and it has been 3 weeks. It's
obvious that I'm still at the beginner level. I find it hard, but I
really really wanna push myself to be good at it. It's probably that I
don't have an organized method that my mind gets messed up easily.

Thank you so much for your respond and suggestion. I will try your
method.

Subject: Am I using the right tool?

From: SEJ080003 student

Date: 25 Oct, 2011 05:01:07

Message: 4 of 8

okay let say I use the "for" loop as the particle released one by one.
I was thinking when you said using "if" condition, do you mean at the
part when I decide to release another particle I have to use rand()
again?? wouldn't it become redundant?

Subject: Am I using the right tool?

From: Claudio

Date: 27 Oct, 2011 15:20:29

Message: 5 of 8

SEJ080003 student <ain_nadrah@siswa.um.edu.my> wrote in message <7ce7c8f2-2426-46f9-97bb-b83a1f937f8f@s35g2000pra.googlegroups.com>...
> okay let say I use the "for" loop as the particle released one by one.
> I was thinking when you said using "if" condition, do you mean at the
> part when I decide to release another particle I have to use rand()
> again?? wouldn't it become redundant?

Hi,
I would consider the loop as the global "time" ticking, so each particle has to obey the same timing.
You can model all the particles with an array of structures:
ReleaseCondition = false;
particle(1).position = [0 0];
particle(1).condition1 = false;
particle(2).position = [1 2];
particle(2).condition1 = false;
n = 2;

for t = 0:1000
   %% calculate new positions
   %% calculate new particle conditions
   %% calculate the release condition

   if ReleaseCondition == true
       ReleaseCondition = false;
       n = n+1;
       particle(n).position = [0 0];
       particle(n).condition1 = false;
   end
end


Good luck!

Subject: Am I using the right tool?

From: SEJ080003 student

Date: 28 Oct, 2011 01:23:59

Message: 6 of 8

Thank you so much for your respond, Claudio. And thank you so much for
introducing that term. I will check more on global time ticking. This
is new to me. =)

Subject: Am I using the right tool?

From: SEJ080003 student

Date: 28 Oct, 2011 01:21:01

Message: 7 of 8

On Oct 27, 11:20 pm, "Claudio " <cverg...@gmail.com> wrote:
> SEJ080003 student <ain_nad...@siswa.um.edu.my> wrote in message <7ce7c8f2-2426-46f9-97bb-b83a1f937...@s35g2000pra.googlegroups.com>...
> > okay let say I use the "for" loop as the particle released one by one.
> > I was thinking when you said using "if" condition, do you mean at the
> > part when I decide to release another particle I have to use rand()
> > again?? wouldn't it become redundant?
>
> Hi,
> I would consider the loop as the global "time" ticking, so each particle has to obey the same timing.
> You can model all the particles with an array of structures:
> ReleaseCondition = false;
> particle(1).position = [0 0];
> particle(1).condition1 = false;
> particle(2).position = [1 2];
> particle(2).condition1 = false;
> n = 2;
>
> for t = 0:1000
>    %% calculate new positions
>    %% calculate new particle conditions
>    %% calculate the release condition
>
>    if ReleaseCondition == true
>        ReleaseCondition = false;
>        n = n+1;
>        particle(n).position = [0 0];
>        particle(n).condition1 = false;
>    end
> end
>
> Good luck!


Thank you so much for your respond. And thank you for introducing that
term. I will check more on global time ticking. This is new to me. =)

Subject: Am I using the right tool?

From: Claudio

Date: 28 Oct, 2011 07:12:15

Message: 8 of 8

> Thank you so much for your respond. And thank you for introducing that
> term. I will check more on global time ticking. This is new to me. =)

You're welcome, but please be aware that "global time ticking" is not a keyword!:D That was just to point out that there is not necessarily a redundancy in the for loop for all the particles.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us