re-looping after terminating

1 visualización (últimos 30 días)
Adeena Naeem
Adeena Naeem el 31 de Ag. de 2019
Respondida: John D'Errico el 31 de Ag. de 2019
I have a code that I want to loop as described below.
  • I want to loop the code 2 times than terminate it.
  • And re-loop again from beginning four times then end it
  • Then re-loop again from beginning 8 times
How would I do that? Many thanks in advance.

Respuestas (1)

John D'Errico
John D'Errico el 31 de Ag. de 2019
Trivial. Put the code INSIDE function. LEARN TO USE FUNCTIONS!!!!!! LEARN TO USE FUNCTIONS! LEARN TO USE FUNCTIONS! There, I said it three times, so it must be true.
Next set up a loop. Run the loop 2 times, or 4 times, or 8 times. As many times as you wish. Something like this:
ncalls = [2 4 8];
for n = 1:numel(ncalls)
for m = 1:ncalls(n)
outputstuff = mycode(inputstuff)
end
end
You don't say what you want your code to do, or what it returns. But save some information if you want, whatever.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by