Effacer les filtres
Effacer les filtres

Matlab sort rows based on last column

4 vues (au cours des 30 derniers jours)
Sucharitha Chokkappa Gari
Sucharitha Chokkappa Gari le 13 Oct 2020
Modifié(e) : Ameer Hamza le 13 Oct 2020
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'

Réponse acceptée

Ameer Hamza
Ameer Hamza le 13 Oct 2020
Modifié(e) : Ameer Hamza le 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, :)

Plus de réponses (0)

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by