Count the number of times a particular sequence occurs in the vector.
3 views (last 30 days)
Show older comments
How to find the number of times and the index a sequence (here 01) occurs in the vector, using for loop?
The vector is randomly generated
A = round(rand(1000,1));
0 Comments
Answers (1)
Bruno Luong
on 15 Nov 2022
Edited: Bruno Luong
on 15 Nov 2022
Not for-loop but it does the job
A=randi(0:1,1,10)
spattern = [0 1];
startidx = strfind(A,spattern)
0 Comments
See Also
Categories
Find more on Resizing and Reshaping Matrices 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!