% Suppose I have a cellarray
C = {[1; 2; 3]; [2; 1; 3, 4]; [3; 1; 2]; [1; 2]}; % where any digit won't repeat in the individual cell.
% I was trying this code
for i = 1:3 for j = 1:3 for k = 1:3 if(i ~= j && i ~= k && j ~= k) % to prevent repetition
sequence_check = [i; j; k]; n = sum(cellfun(@(x) ~isempty(strfind(x.',sequence_check.')), C)); t = table(i, j, k, n) end end end end% which gives me possible sequences (using 1,2 and 3) | number of occurrences
123 | 1132 0213 1231 0312 1321 0% I need to find out the maximum number of occurrences of the sequences inside the cell array beginning with 1 or 2 or 3 individually.
% Expected output:
123 | 1213 1312 1
MATLAB: How to find out the maximum number of occurrences of the sequences inside the cell array beginning with particular digit
cell arraysequence finder
Related Question
- How to count the number of occurrences of each pair in a cell
- Matrix Manipulation
- Find unique or duplicate cells in cell array of chars
- Initializing Matrix for all possible sequences of numbers
- Multidimensional array to column vector with different dimensional order
- How to automate the count of consecutive values in a cell array
Best Answer