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?
显示 更早的评论
Not sure where to start this is my second time using MATLAB, thanks!
1 个评论
Jan
2013-1-24
Please try it. What are the indices of the 1s?
回答(3 个)
Walter Roberson
2013-1-24
1 个投票
Hint: the indices sum to 5.
1 个评论
Jan
2013-1-24
+1: This is no solution of a homework question.
Michael Joslin
2013-1-24
编辑:Michael Joslin
2013-1-24
0 个投票
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
2013-1-24
编辑:Sean de Wolski
2013-1-24
I = fliplr(eye(4));
2 个评论
Walter Roberson
2013-1-24
This does not go top right to bottom left.
Sean de Wolski
2013-1-24
fixed
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!