Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

How to do the loop

1 visualización (últimos 30 días)
Aswin Sandirakumaran
Aswin Sandirakumaran el 5 de Mayo de 2018
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
I have a vector A = [0,0,0] & B = [4,2,1]
i = 1:length(B) -->> I am not sure about this part
while (A(i) <= B(i))
A(i) = A(i) + 1;
end
I need to perform this while loop according to B values. To give you a clear picture; first while loop should consider B(1) which is 4. Therefore while loop should be carried out 4 times. here the output will of A will change to A = [4,0,0]. Once done, B(2)--> which is 2. So while loop should be done 2 times and o/p now will be A = [4,2,0] and then B(3) ---> which is 1. So the Final output of A will be [4,2,1] instead of [0,0,0].
  1 comentario
Dennis
Dennis el 5 de Mayo de 2018
to make your code work you just need to add 'for'
for it = 1:length(B)
while (A(it) <= B(it))
A(it) = A(it) + 1;
end
end
However it might be possible to avoid using multiple loops, depending on what you want to do. Right now A=B would do the trick but i assume thats not what you actually want.

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by