repeat the code with different value each time
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi
I have a matrix w= 6x222 . I have 37 window. I want to repeat the code with different w 37 times. First I use the the first 6 columns of w so I use W=w(:,[1:6]); and I have the results then I use the following 6 columns i.e.W=w(:,[7:12]); and so on untile I have the last 6 columns W=w(:,[217:222]);
How can I do this iteration and extract the 37 solutions from each W.
Thanks in advance
0 Kommentare
Akzeptierte Antwort
Jan
am 5 Mär. 2023
Bearbeitet: Jan
am 5 Mär. 2023
w = rand(6, 222);
index = 1:6:size(w, 2);
result = zeros(1, numel(index));
for k = 1:numel(index)
aw = w(:, index(k):index(k)+5); % A 6x6 submatrix
result = yourCalculations(aw);
end
I'd avoid the names "w" and "W", because the letters can be confused easily.
A more Matlab'ish way:
ww = reshape(w, 6, 6, []);
Now the calculations might be applicable to the 3D array ww directly without a loop. See e.g. pagemldivide or pagemtimes.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Linear Programming and Mixed-Integer Linear Programming finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!