Vector from loop - stop after x numbers of iterations

3 visualizaciones (últimos 30 días)
Mikel Jimenez
Mikel Jimenez el 11 de Feb. de 2023
Comentada: Mikel Jimenez el 13 de Feb. de 2023
Hi,
I have this loop here:
n_trial = 12;
n_probe =7;
longer_array = [1:96];
updated_probeNum_withinBlock=0;
for trial = 1:n_trial
for probe = 1:n_probe
probeNum_withinBlock=longer_array((trial-1)*n_probe+probe+updated_probeNum_withinBlock); %index into your longer_array
end
probeNum_withinBlock= (probeNum_withinBlock+1);
updated_probeNum_withinBlock= (1+updated_probeNum_withinBlock);
end
I need a similar vector to "probeNum_withinBlock" but that stops after the 48th iteration (e.g., I need this vector to be a 1 x 48 array, from 1 to 48). It seems that I cannot find the correct way to do this.
Any help would be very much appreciated.
  7 comentarios
Walter Roberson
Walter Roberson el 12 de Feb. de 2023
n_trial = 12;
n_probe =7;
longer_array = [1:96];
updated_probeNum_withinBlock=0;
for trial = 1:n_trial
for probe = 1:n_probe
probeNum_withinBlock=longer_array((trial-1)*n_probe+probe+updated_probeNum_withinBlock); %index into your longer_array
if trial <= 7
probe_record(probe,trial) = probeNum_withinBlock;
end
end
probeNum_withinBlock= (probeNum_withinBlock+1);
updated_probeNum_withinBlock= (1+updated_probeNum_withinBlock);
end
probe_record = probe_record(:); %make it a vector
But unless n_trial is a lot larger than the cutoff point (7), most people would simply record all of the outputs and then later throw away the ones they do not need.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by