Iteration over for loop using a vector
16 次查看(过去 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
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!