Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私は次のようなマトリックスを持っています
a = 1 3 2 5 3 2 4 8 5 9
aマトリックスの 2 列目を並べ替えたい。列1の対応する行を次のように印刷したい:
a
a = 3 2 1 3 2 5 4 8 5 9
試してみsort(a)たのですが、matrix の 2 列目だけをソートしていますa。
sort(a)
これを試して:
sortrows(a,2)
これは、2 番目の列に従って並べ替える必要があります。
または使用:
[val idx]=sort(a(:,2)); ans = [a(idx,1) val]