Iteration over for loop using a vector

11 Ansichten (letzte 30 Tage)
Mikel Jimenez
Mikel Jimenez am 2 Feb. 2023
Kommentiert: Mikel Jimenez am 3 Feb. 2023
Hi,
I want to run a for loop (the "for probe = 1:n_trial" in the example below) for a specific number of times (e.g., 7). However, I want it to continue the iteration over a longer vector array (e.g., "longer_array" with 84 values). Every time the loop comes back, it should continue iterating on that vector (for example, the first time it would go from 1 to 7, the second time from 8 to 14, etc.).
I'm not sure if I'm explaining myself correctly. Anyway, here an example of the code:
n_trial = 12;
n_probe =7;
longer_array = [1:84];
for trial = 1:n_trial
for probe = 1:n_probe
%do something here
end
%do something here
end
Any help with this would be very much appreciated.
Thanks,
Mikel

Akzeptierte Antwort

David Hill
David Hill am 2 Feb. 2023
n_trial = 12;
n_probe =7;
longer_array = [1:84];
for trial = 1:n_trial
for probe = 1:n_probe
longer_array((trial-1)*n_probe+probe);%index into your longer_array
end
%not sure what you want to do here, explain
end

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by