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?

回答 (3 件)

Walter Roberson
Walter Roberson 2013 年 1 月 24 日
Hint: the indices sum to 5.
Michael Joslin
Michael Joslin 2013 年 1 月 24 日
編集済み: Michael Joslin 2013 年 1 月 24 日
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
Sean de Wolski 2013 年 1 月 24 日
編集済み: Sean de Wolski 2013 年 1 月 24 日
I = fliplr(eye(4));

2 件のコメント

This does not go top right to bottom left.
fixed

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeOperating on Diagonal Matrices についてさらに検索

質問済み:

2013 年 1 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by