Using a matrix as an index of another matrix
조회 수: 2(최근 30일)
표시 이전 댓글
Hello everybody, I need some help please!
I am trying to sort a matrix (x) and go back to the original order based on the index matrix (idx2).
a = 30.0;
b = 100.0;
for i=1:5
x = (b-a).*rand(5,5) + a;
x = round(x,1);
end
[y, idx2] = sort(x, 2);
Thank you in advance
댓글 수: 0
답변(1개)
Steven Lord
2023년 3월 10일
Take some shuffled data.
r = randperm(10)
Now sort it.
[sortedData, indices] = sort(r)
We can get back to r from sortedData using the indices.
recreatedR(indices) = sortedData
Let's check.
isequal(r, recreatedR)
We could also recreate sortedData from r using indices.
isequal(sortedData, r(indices))
참고 항목
범주
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!