看板 MATLAB 關於我們 聯絡資訊
最近才開始接觸MATLAB 問的問題可能有點淺 還勞煩各位回答我的問題了@@.... =============== 念到sort 書上的範例在說 x=[3 5 8 1 4] [sorted, index]=sort(x) 就會出現 sorted= 1 3 4 5 8 index= 4 1 5 2 3 請問要如何使用sorted跟index求得原向量x -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.243.120.160 ※ 文章網址: http://www.ptt.cc/bbs/MATLAB/M.1409654372.A.EB1.html
kurt28: unique可以作到你要的 sort我就不知道了@@ 09/02 20:19
kurt28: 剛試了一下 [~,index2]=sort(index); sorted(index2); 09/02 20:23
profyang: 我倒是比較好奇什麼情況需要反求原來的向量呢?@@ 存起來 09/02 21:11
profyang: 不就好了嗎? 09/02 21:11
jatj: 有時候要知道"這個元素在原來矩陣的哪個位置" 09/03 03:21
jatj: 那index就很好用了 09/03 03:21
kurt28: 推樓上 index真的很好用~ 原PO可以考慮直接用unique 09/03 12:22
kurt28: 可以直接得到兩邊的index 09/03 12:22
shane: y=zeros(size(x)),y(ind)=sorted 09/03 19:07
profyang: 對阿~應該頂多就是需要到index吧 不知道為啥需要還原 09/03 19:09
alan23273850: 感謝原PO,這篇文到了2017年仍受惠,index真的讚讚 10/14 12:01
alan23273850: 祝樓主一生平安 10/14 12:01