フィルターのクリア

interpret a simple matrix code

1 回表示 (過去 30 日間)
Ann Lee
Ann Lee 2022 年 4 月 29 日
コメント済み: Ann Lee 2022 年 4 月 29 日
I m interpret a very easy code...
I don't know some points, could you explain green sentences?
>> A=eye(4,4)
A =
Diagonal Matrix
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
>> for x=(1:2:3) %what is this mean x=(1:2:3)
A(x,x)=x+1; % first x is line and second x is row right? hence it means (1,1), (2,2), (3,3),(4,4)
end
>> A
A =
Diagonal Matrix
2 0 0 0
0 1 0 0
0 0 4 0
0 0 0 1

採用された回答

Jan
Jan 2022 年 4 月 29 日
I recommend to use the free Matlab tutorials to learn the basics: https://www.mathworks.com/learn/tutorials/matlab-onramp.html
Read the "Getting Started" chapters of the documentation also.
If you have a question about a for loop, read:
help for
doc for
Here your find what a:b:c means: "initVal:step:endVal"
"hence it means (1,1), (2,2), (3,3),(4,4)" - almost correct: The loop stops at 3, so (4,4) is not included.
  1 件のコメント
Ann Lee
Ann Lee 2022 年 4 月 29 日
thank you! i'll read that tutorials!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by