The last statement you show is vectorized, so the question is ill-posed. I think what you are asking for is a way to speed up the process.
Also, just how fast do you think it should be??
x = zeros(1000,1);
x(76) = 1;
x(100) = 1;
x(200) = 1;
tic,first = find(x ==1, 1, 'first');toc
Elapsed time is 0.000023 seconds.
.
.
.
EDIT
I did find a way to do it faster, but it will only work if you have a binary matrix as in your example. You can avoid the comparison as it is not necessary.
tic,first = find(x);first = first(1);toc
Elapsed time is 0.000012 seconds.
1 Comment
Direct link to this comment
https://nl.mathworks.com/matlabcentral/answers/56331-how-to-vectorize-a-find#comment_122746
Direct link to this comment
https://nl.mathworks.com/matlabcentral/answers/56331-how-to-vectorize-a-find#comment_122746
Sign in to comment.