Iteration over for loop using a vector

11 次查看(过去 30 天)
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

采纳的回答

David Hill
David Hill 2023-2-2
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by