how to avoid for loop
Show older comments
can this 'for loop' be replaced? thanks in advance
counts=[];
for i=1 : length(b)-1
c=length(tof( tof >= b(i) & tof < b(i+1)) ) ;
counts=[counts,c];
end
Accepted Answer
More Answers (1)
Image Analyst
on 7 Nov 2019
Try this (untested)
lastIndex = length(b)-1;
indexes = (tof > b(1:lastIndex)) & (tof < b(2:lastIndex + 1));
counts = cumsum(indexes)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!