Iteration over for loop using a vector
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mikel Jimenez
el 2 de Feb. de 2023
Comentada: Mikel Jimenez
el 3 de Feb. de 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
0 comentarios
Respuesta aceptada
David Hill
el 2 de Feb. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!