Matlab sorting matrix with index (smallest to biggest)

4 ビュー (過去 30 日間)
Erel Kasirga
Erel Kasirga 2019 年 6 月 1 日
コメント済み: KALYAN ACHARJYA 2019 年 6 月 1 日
Lets say that i got a Location matrix like
Location=[673.725,10355.05,7650.4,5219.5,5776.125,6641.175,4374.525,3847.1,6429.475,5396.525,5219.5,4182.9,7391.25,5038.825,10349.575,6051.7]
and i want to sort this matrix with index. I search the internet and i wrote this code ;
m=16;n=1;
custom=zeros(n,m);
sortedDist=zeros(n,m);
for i=1:n
[sortedDist(i,:),index]=sort(Location(i,:),'ascend');
custom(i,:)=index;
end
But in the end it doesnt sorted indexs the way i need. I want the indexs of the matrix which is sorted smallest to biggest. How can i do that ?

採用された回答

Stephen23
Stephen23 2019 年 6 月 1 日
Get rid of the loop:
[sortedDist,idx] = sort(Location,'ascend')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by