Using while loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am performing a series of calculations on a matrix in a while loop. The output matrix from the series of calculations is what determines whether the next cycle takes place or not. But then how do i make the input to the calculations stage be the output of the previous iteration or is this what matlab performs in the while loop anyway? Thanks
0 comentarios
Respuestas (2)
Sean de Wolski
el 11 de Abr. de 2012
That's what it does anyway. Maybe this will help explain:
M = magic(5)
while ~isempty(M)
M(1,:) = []
end
0 comentarios
Sargondjani
el 11 de Abr. de 2012
actually this is very simple. if you do some calculations in your while looop, and assign a value to some variable, then this variable will keep this value in the next cycle... until you overwrite it. if you want to do calculations with this variable than you will have the initialize it before the while loop;
OUTPUT=OUTPUT0; %initialization
while %your statement
%calculations, probably involving variable 'OUTPUT'
OUTPUT = % the number you want it to be.
end
of course, you can also store the value of OUTPUT in a vector, or matrix, array or whatever so you can track it afterwards. This would look like this if OUTPUT has to contain an array (replace {} with () if OUTPUT has just 1 value):
iter =1;
OUTPUT{iter}=OUTPUT0;
while
%calculations with OUTPUT{iter}
iter=iter+1;
OUTPUT{iter}=
end
I hope this answers your question...
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!