Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to get the indices of the rows of the matrix which are shuffled ?

1 回表示 (過去 30 日間)
HIRAKJYOTI BASUMATARY
HIRAKJYOTI BASUMATARY 2017 年 11 月 18 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have a matrix A , which i have shuffled. Now how to get the indices of the rows which were shuffled . Just like the command 'sort' gives the indices of the elements sorted. Similarly , is there a command which would give me the indices of the rows interchanged. Please suggest . Thanks
function trial
A=[3 2 1;4 5 6;6 7 8];
shuffledArray = A(randperm(size(A,1)),:)
end
  2 件のコメント
per isakson
per isakson 2017 年 11 月 18 日
編集済み: per isakson 2017 年 11 月 18 日
>> A
A =
3 2 1
4 5 6
6 7 8
>> ix = randperm(size(A,1))
ix =
3 1 2
>> A(ix,:)
ans =
6 7 8
3 2 1
4 5 6
Isn't it ix you are looking for?
HIRAKJYOTI BASUMATARY
HIRAKJYOTI BASUMATARY 2017 年 11 月 18 日
編集済み: HIRAKJYOTI BASUMATARY 2017 年 11 月 18 日
Yes . So this way, i should first find the indices and then do the swap. Thank you very much for the suggestions

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 11 月 18 日
sortrows()

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by