Extract arrays of a matrix using FOR loop
6 views (last 30 days)
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
0 Comments
Answers (1)
AKAYDIN
on 19 Jan 2023
A = rand(10,10) % random matrix when n=10
for i=1:length(A)
diagonal(i) = A(i,i);
end
diagonal
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements 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!