Iteration over for loop using a vector

14 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

David Hill
David Hill il 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

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by