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:
help in for function

Subject: help in for function

From: mahdi roozbhani

Date: 22 Dec, 2010 02:16:04

Message: 1 of 2

friends, I have a code in below :

x=[1 2 2 3 4];
sx=size(x);

for i=1:3
randx=randi(sx(2),1,1);
e=x(randx);
if e==2
p(i)=e;
else
i=i-1;
end
end

for example in the i equal to 3,if e is equal 2; do the third(3th) loop again.

but it does not work, please help me.
for example, I want to repeat counter i in 3rd level for several time.

Subject: help in for function

From: LE Thanh

Date: 22 Dec, 2010 07:16:04

Message: 2 of 2

"mahdi roozbhani" <m.m.roozbahani@gmail.com> wrote in message <iern14$cjb$1@fred.mathworks.com>...
> friends, I have a code in below :
>
> x=[1 2 2 3 4];
> sx=size(x);
>
> for i=1:3
> randx=randi(sx(2),1,1);
> e=x(randx);
> if e==2
> p(i)=e;
> else
> i=i-1;
> end
> end
>
> for example in the i equal to 3,if e is equal 2; do the third(3th) loop again.
>
> but it does not work, please help me.
> for example, I want to repeat counter i in 3rd level for several time.

I don't think I understand your problem. Please show it more clearly!

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