How to sort the data with respect to a column in matlab
古いコメントを表示
Lets say....A matrix PhysicalData is a 18X12 matrix. And i want to sort all the rows, in the ascending order of value in any column (Lets say 15th column). So the Row corresponding to the lowest value in 15th column should come first and so on. Please help me out. Thanks
採用された回答
その他の回答 (1 件)
Ameetha
2022 年 9 月 19 日
0 投票
How to sort a table based on a particular column in ascending order whose elements are names of images saved in the order 1.jpg,2.jpg...... When sortrows command is used its getting sorted as 1.jpg, 10.jpg, 100.jpg etc
5 件のコメント
Ameetha
2022 年 9 月 19 日
I want to get the rows sorted in the order 1.jpg, 2.jpg...
Stephen23
2022 年 9 月 19 日
Download NATSORTROWS and follow its documentation:
Ameetha
2022 年 9 月 19 日
Hey Stephen, Thanks on your quick response.
But I dont know how to give the syntax as I'm getting errors while using natsortrows. My Table is ' Data'. Want to arrange the table rows in the increasing order of the column 'ImageName', where names are in some random order 4.jpg, 32.jpg....
I get this error while using this code,
Data1 = natsortrows(Data,ImageName);
Error using natsort (line 190)
Second input <rgx> must be a character row vector or a string scalar.
Error in natsortrows (line 389)
[~,idx] = natsort(tmp,txt{:},xtx{:});
Kindly help.
The NATSORTROWS documentation states that the second input argument is reserved for specifying a regular expression (if used). This is explained in the Mfile help and in the HTML help.
To specify the table variable/column name to sort, then this can be provided as input 3 (or greater):
Data1 = natsortrows(Data, [], 'ImageName');
An alternative approach is to sort that variable/column using NATSORTFILES and then use the sort index to sort the table into the same order:
[~,idx] = natsortfiles(Data.ImageName);
Data1 = Data(idx,:)
Ameetha
2022 年 9 月 19 日
[~,idx] = natsortfiles(Data.ImageName);
Data1 = Data(idx,:)
Thanks a lot. It actually worked. Thank you so much.
カテゴリ
ヘルプ センター および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!