Clear Filters
Clear Filters

Matlab sort rows based on last column

4 views (last 30 days)
This is my data which is in form of cells and I want to sort this based on last column. last column has mixture of 7 digited and 8 digited numbers. how can I sort this.
If im using cell2mat to last column it is showing dimension error
'die4' '3' '0' '3424000' '15884653'
'die4' '3' '0' '3424000' '15884653'
'die4' '4' '0' '174000' '16002122'
'die4' '4' '0' '174000' '16002122'
'die4' '3' '1400000' '3724000' '16700362'
'die4' '1' '5200000' '8624000' '8989534'
'die4' '1' '5200000' '8624000' '9031330'
'die4' '1' '4598880' '8624000' '9141137'
'die4' '1' '4598880' '8624000' '9182932'
'die4' '4' '5300000' '3474000' '9995480'
'die4' '4' '5300000' '3474000' '9995480'

Accepted Answer

Ameer Hamza
Ameer Hamza on 13 Oct 2020
Edited: Ameer Hamza on 13 Oct 2020
It appears that your data is available in string format. First, convert it to double and then sort
C; % your cell array
C_last = cellfun(@str2double, C(:,end)); % convert last column to numeric format
[~, idx] = sort(C_last);
C_sorted = C(idx, :)

More Answers (0)

Categories

Find more on Statistics and Machine Learning Toolbox 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!