How can generalize several "For loop" ?

1 visualización (últimos 30 días)
STamer
STamer el 20 de Feb. de 2013
Hello;
I want to generalize the expression.It goes "for i=5:n"......"for i=n:n".
I tried nested loop statement but couldn't manage..Is there any help? Thanks and regards
A=input('Enter nxn matrix:')
B=input('Enter solution matrix(n*1):')
[n n]=size(A);
L=zeros(n);
for i=1:n
L(i,i)=1;
end
for i=2:n
L(i,1)=A(i,1)/A(1,1);
end
for i=3:n
L(i,2)=A(i,2)/A(2,2);
end
for i=4:n
L(i,3)=A(i,3)/A(3,3);
end

Respuesta aceptada

Babak
Babak el 20 de Feb. de 2013
A=input('Enter nxn matrix:')
B=input('Enter solution matrix(n*1):')
[n n]=size(A);
L=zeros(n);
for i=1:n
L(i,i)=1;
end
for k = 1:n
for i=k+1:n
L(i,k)= A(i,k)/A(k,k);
end
end

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by