Count the number of times a particular sequence occurs in the vector.

4 Ansichten (letzte 30 Tage)
Sivaranjani
Sivaranjani am 15 Nov. 2022
Bearbeitet: Bruno Luong am 15 Nov. 2022
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));

Antworten (1)

Bruno Luong
Bruno Luong am 15 Nov. 2022
Bearbeitet: Bruno Luong am 15 Nov. 2022
Not for-loop but it does the job
A=randi(0:1,1,10)
A = 1×10
1 0 1 0 1 0 1 0 0 0
spattern = [0 1];
startidx = strfind(A,spattern)
startidx = 1×3
2 4 6

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by