Need for explication of this code

1 回表示 (過去 30 日間)
Rmc Yasmina
Rmc Yasmina 2019 年 10 月 23 日
回答済み: CAM 2019 年 10 月 24 日
I need explication of this code
V=(1:50);
I=3;
J=4;
M=[];
for i=1:J:I*J
M=[M;V(i:i+I)];
end;
  2 件のコメント
Ruger28
Ruger28 2019 年 10 月 23 日
This "code" isn't even finished...
Alex Mcaulley
Alex Mcaulley 2019 年 10 月 24 日
Put a breakpoint in this line:
M=[M;V(i:i+I)];
and see what is happening in each iteration

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

採用された回答

CAM
CAM 2019 年 10 月 24 日
"i" starts with 1. M becomes [V(1:(1+3))] = [1:4] = [1 2 3 4].
"i" becomes 5 = (1+J) = (1+4). M adds a row with [5 6 7 8]. Etc...
Ultimately, this will give you the numbers 1 through 12 in a 4x3 matrix.
1 2 3 4
5 6 7 8
9 10 11 12
Why use all that code when you could use: M=reshape([1:12], 4,3) ?

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by