Vector from loop - stop after x numbers of iterations
3 次查看(过去 30 天)
显示 更早的评论
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
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.
回答(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!