Vector from loop - stop after x numbers of iterations

3 vues (au cours des 30 derniers jours)
Mikel Jimenez
Mikel Jimenez le 11 Fév 2023
Commenté : Mikel Jimenez le 13 Fév 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 commentaires
Walter Roberson
Walter Roberson le 12 Fév 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.
Mikel Jimenez
Mikel Jimenez le 13 Fév 2023
Thanks a lot

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by