How can I create a simple matrix of 4 by 4 using a "for" loop. to make a diagnol of 1's starting from top right to bottom left?
Show older comments
Not sure where to start this is my second time using MATLAB, thanks!
1 Comment
Jan
on 24 Jan 2013
Please try it. What are the indices of the 1s?
Answers (3)
Walter Roberson
on 24 Jan 2013
1 vote
Hint: the indices sum to 5.
1 Comment
Jan
on 24 Jan 2013
+1: This is no solution of a homework question.
Michael Joslin
on 24 Jan 2013
Edited: Michael Joslin
on 24 Jan 2013
0 votes
Heres a way to do it without a for loop if your interested:
a = ones(4); a = diag(diag(a)); rot90(a)
This might not be too helpful if all of your other elements are not zero.
Sean de Wolski
on 24 Jan 2013
Edited: Sean de Wolski
on 24 Jan 2013
I = fliplr(eye(4));
2 Comments
Walter Roberson
on 24 Jan 2013
This does not go top right to bottom left.
Sean de Wolski
on 24 Jan 2013
fixed
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!