How can I sort data in increasing order
5 次查看(过去 30 天)
显示 更早的评论
I have been given this data
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/748864/image.png)
I want to classify the length in each row as either the shortest(S), longest(L), or other (P or Q) so i can use this equation S+L=P+Q
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/748869/image.png)
Here is my code so far.
3 个评论
Image Analyst
2021-9-27
@JAKE WISNIEWSKI, Why can't you do it now? All I can suggest is to use sort() or sortrows(). And I'm not sure I buy this equation
S+L=P+Q
What makes you think it will be true? For example for one row where the L's are [6,2,7,9] you have
2 + 9 = 6 + 7
or
11 = 13
which is obviously not true.
回答(1 个)
Sulaymon Eshkabilov
2021-9-24
Use sort() that sorts in an ascending order and then take the indexes that will be used for the others, OR put in a table using array2table() and sort them in order.
0 个评论
另请参阅
类别
在 Help Center 和 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!