Search code examples
arraysstringmatlabcell

MATLAB partition cell array


I have a cell array such that it is 128 characters long, i.e

c = {'1......128'}

What I'd like to do is break it up into chunks of 8, starting from the left, then put each 8-chunk piece into a new cell array. What is the easiest way to do this?


Solution

  • You can do it with one line

    mycell = repelem('a', 128); % creating the cell
    
    newcells = cellstr(reshape(mycell{:},8,[])'); % cells with 8 characters each
    

    if your cell is just 1x1 with 128 characters.