Info
この質問は閉じられています。 編集または回答するには再度開いてください。
How to have array in for loop
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
So I have a matrix and I want to divide some columns by other columns in a for loop, because I want to divide sets of 3 columns by different sets, so i have created this example:
one=1:24;
two= 25:48;
three=49:72;
four=73:96;
M=[one;two;three;four]
for i=1:4
for j=1:3
Mnew(i,j)=M(i,j)./M(i,16:18);
end
for j=4:6
Mnew(i,j)=M(i,j)./M(i,19:21);
end
end
How can I make j=1:3 literally an array such as 16:18, because now it won't let me run this.
0 件のコメント
回答 (1 件)
Alan Stevens
2020 年 9 月 23 日
Like so:
one=1:24;
two= 25:48;
three=49:72;
four=73:96;
M=[one;two;three;four];
for i=1:4
j = 1:3;
Mnew(i,j)=M(i,j)./M(i,16:18);
j = 4:6;
Mnew(i,j)=M(i,j)./M(i,19:21);
end
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!