Vector from loop - stop after x numbers of iterations

3 ビュー (過去 30 日間)
Mikel Jimenez
Mikel Jimenez 2023 年 2 月 11 日
コメント済み: Mikel Jimenez 2023 年 2 月 13 日
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 件のコメント
Walter Roberson
Walter Roberson 2023 年 2 月 12 日
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 2023 年 2 月 13 日
Thanks a lot

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by