Matlab sort rows based on last column

4 次查看(过去 30 天)
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'

采纳的回答

Ameer Hamza
Ameer Hamza 2020-10-13
编辑:Ameer Hamza 2020-10-13
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, :)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by