Extract arrays of a matrix using FOR loop
Show older comments
Hello everyone
the question is: Write a code using FOR loop that extract Main diagonal of any n*n matrix.
i know diag will do the job but i wanna write it with FOR loop
Thanks in advance
Answers (1)
A = rand(10,10) % random matrix when n=10
for i=1:length(A)
diagonal(i) = A(i,i);
end
diagonal
Categories
Find more on Operating on Diagonal Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!