While loop keep running (logical with vector )
Mostrar comentarios más antiguos
Hi all,
My while loop running without stopping, I wanna it run until reach to logical function of a equal or smaller than 10. which should be any two numbers a=[6 3] or a=[6 6]
thanks,
clearvars;
clc;
a=[0 0];
while all(a)<=6
z=[6 10 8 9 22 3 6];
for i=1:2
z(i)=z(randi(end));
a(i)=z(i)+1
end
end
2 comentarios
Ameer Hamza
el 10 de Sept. de 2020
Can you describe the condition more clearly?
Ali Tawfik
el 10 de Sept. de 2020
Respuesta aceptada
Más respuestas (1)
BOB MATHEW SYJI
el 10 de Sept. de 2020
0 votos
I think replacing while with if solves the problem
clearvars;
clc;
a=[0 0];
if all(a)<=6
z=[6 10 8 9 22 3 6];
for i=1:2
z(i)=z(randi(end));
a(i)=z(i)+1
end
end
1 comentario
Ali Tawfik
el 10 de Sept. de 2020
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!