How to find the number of occurrences of a particular sequence inside the cell array?
5 views (last 30 days)
Show older comments
Md Shahidullah Kawsar
on 16 Nov 2018
Edited: Bruno Luong
on 16 Nov 2018
% Suppose I have a cellarray
C = {[1; 2; 3]; [1; 2; 3; 4]; [4; 1; 2; 3]; [1; 2]};
c{:}
ans =
1
2
3
ans =
1
2
3
4
ans=
4
1
2
3
ans=
1
2
% where any digit won't repeat in the individual cell.
% I need to find out: how many times a particular sequence is present inside the cell array.
Expected output:
sequence_check = {[1; 2; 3]}
Number_Of_Times_that_sequence_is_Present_Inside_the_Cell_Array = 3
Show_the_index_of_those_cells = 1 2 3
0 Comments
Accepted Answer
Bruno Luong
on 16 Nov 2018
Edited: Bruno Luong
on 16 Nov 2018
C = {[1; 2; 3]; [1; 2; 3; 4]; [4; 1; 2; 3]; [1; 2]};
sequence_check = [1; 2; 3];
n = sum(cellfun(@(x) ~isempty(strfind(x.',sequence_check.')), C))
0 Comments
More Answers (0)
See Also
Categories
Find more on Whos 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!