How to have array in for loop
Informazioni
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Mostra commenti meno recenti
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.
Risposte (1)
Alan Stevens
il 23 Set 2020
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
Questa domanda è chiusa.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!