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:
what is command for repeat?

Subject: what is command for repeat?

From: apple

Date: 5 Apr, 2009 06:32:03

Message: 1 of 5

i'm doing the homework about finding the largest number and i found the key word is used the flow chart. so, i tried to create the command for repeat.. however it show error undefined the word REPEAT. so what is the command for repeat?
and this are the flow chart related with my program

http://www.edrawsoft.com/images/examples/Sum%20of%20first%2050%20natural%20numbers.png

Subject: what is command for repeat?

From: Matt Fig

Date: 5 Apr, 2009 06:47:03

Message: 2 of 5

At the Matlab prompt, type:

doc for

Read everything, and when you are done click the link at the bottom of the page to read about the While loop. Also you should read about the If statement.

Subject: what is command for repeat?

From: Roger Stafford

Date: 5 Apr, 2009 07:47:36

Message: 3 of 5

"apple " <Quixotic04@yahoo.com> wrote in message <gr9j93$bu7$1@fred.mathworks.com>...
> i'm doing the homework about finding the largest number and i found the key word is used the flow chart. so, i tried to create the command for repeat.. however it show error undefined the word REPEAT. so what is the command for repeat?
> ........

  Unfortunately there is no "repeat-until" command in the matlab language. I have often wished there were. In my opinion Mathworks made an error in judgement in omitting it from their repertoire.

  The closest thing to it is the "while-loop" and you can always simulate the "repeat-until" action using the "while" construction and the appropriate boolean(s), but sometimes that can be a nuisance. Here's an example:

 % The non-existant "repeat" command
 c = 0;
 repeat
  x = rand;
  y = rand;
  z = rand;
  c = c+1;
 until x+y+z > 2.999;

 % Simulation with "while-loop"
 c = 0;
 b = true;
 while b
  x = rand;
  y = rand;
  z = rand;
  c = c+1;
  b = x+y+z > 2.999;
 end

Roger Stafford

Subject: what is command for repeat?

From: Roger Stafford

Date: 5 Apr, 2009 11:24:01

Message: 4 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gr9nmo$h5u$1@fred.mathworks.com>...
> .......
> % The non-existant "repeat" command
> c = 0;
> repeat
> x = rand;
> y = rand;
> z = rand;
> c = c+1;
> until x+y+z > 2.999;
>
> % Simulation with "while-loop"
> c = 0;
> b = true;
> while b
> x = rand;
> y = rand;
> z = rand;
> c = c+1;
> b = x+y+z > 2.999;
> end
> ......

  Whoops! I got that while-loop logic backwards. Sorry about that. To be equivalent to the "repeat" construct, it should be:

 ...
 b = true;
 while b
  ....
  b = x+y+z <= 2.999
 end

(It should require quite a few passes through the loop before that boolean becomes false, somewhere in the neighborhood of six billion.)

Roger Stafford

Subject: what is command for repeat?

From: Bruno Luong

Date: 5 Apr, 2009 11:46:02

Message: 5 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gr9nmo$h5u$1@fred.mathworks.com>...
> "apple " <Quixotic04@yahoo.com> wrote in message <gr9j93$bu7$1@fred.mathworks.com>...
> > i'm doing the homework about finding the largest number and i found the key word is used the flow chart. so, i tried to create the command for repeat.. however it show error undefined the word REPEAT. so what is the command for repeat?
> > ........
>
> Unfortunately there is no "repeat-until" command in the matlab language. I have often wished there were. In my opinion Mathworks made an error in judgement in omitting it from their repertoire.
>
> The closest thing to it is the "while-loop" and you can always simulate the "repeat-until" action using the "while" construction and the appropriate boolean(s), but sometimes that can be a nuisance. Here's an example:
>
> % The non-existant "repeat" command
> c = 0;
> repeat
> x = rand;
> y = rand;
> z = rand;
> c = c+1;
> until x+y+z > 2.999;
>

May be this syntax of WHILE "looks" closer REPEAT:

while true
   x = rand;
   y = rand;
   z = rand;
   c = c+1;
  if x+y+z > 2.999
     break;
  end
end

Bruno

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