MATLAB: How to mat2cell the array

cell arraycell arrays

Suppose I have this:
v= {1 8 1 1 6 1 2 5 3 2 7 11 7 9 10 9};
How can I mat them as below? ( with array start and end as same number)
v= { [1 8 1] [1 6 1] [2 5 3 2] [7 11 7] [9 10 9] };

Best Answer

  • >> v = {1,8,1,1,6,1,2,5,3,2,7,11,7,9,10,9};
    >> c = regexp(char([v{:}]),'(.).*?(??$1)','match');
    >> c = cellfun(@double,c,'uni',0);
    >> c{:}
    ans =
    1 8 1
    ans =
    1 6 1
    ans =
    2 5 3 2
    ans =
    7 11 7
    ans =
    9 10 9