Search code examples
matlabsortingcell

How to rearrange the content of a cell in MATLAB?


I import a group of time series into a cell in MATLAB, the each time series has different dimension. The cell looks like below:

datacell = 

[176x1 double] [132x1 double] [129x1 double] [86x1 double] [90x1 double] ...[162x1 double] 

I want to rearrange the cell, from lowest dimension to the largest, from left to right. There are 1000 entries in the cell, there is no way to do this mannually. How can I do this? Please someone give some ideas on handling this.

Thanks!


Solution

  • Simple:

    [~, I] = sort(cellfun(@length, datacell));
    new_datacell = datacell(I);