Rewrite function for loop in while

2 visualizaciones (últimos 30 días)
steve Brian
steve Brian el 17 de Abr. de 2020
Respondida: David Hill el 17 de Abr. de 2020
Hi all! How can I rewrite this for loop in a while?
for i = 2:sum(1: (rows - 1))
if (i > sum(1: (x)))
x ++;
endif
if ( (i == sum(1:(x))) || (i == sum(1: (x - 1)) + 1))
A(i,i) = 5;
else
A(i,i) = 6;
endif
endfor

Respuesta aceptada

David Hill
David Hill el 17 de Abr. de 2020
i=2;
while i <= sum(1:rows-1)
if i > sum(1:x)
x=x+1;
end
if (i == sum(1:x)) || (i == sum(1:x-1)+1)
A(i,i) = 5;
else
A(i,i) = 6;
end
i=i+1;
end

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by