How to have array in for loop
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
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!