shuffle indexes when sorting matrix
Ältere Kommentare anzeigen
Hi everyone,
I am in urgent need for a solution as I am really stuck!
I have a matrix "image" that needs to be sorted per column and I did that by:
[~, index_sorted] = sort(image,2,'descend');
which works fine and I have the indexes of the elements sorted.
However, image contains a lot of repeated values and when I order the indexes I always obtain the values in order.
So for example, if image is:
image = [0 0 0 -1; 0 0 -1 0; 1 1 0 0; 0 2 0 0]
index_sorted = [1 2 3 4; 1 2 4 3; 1 2 3 4; 2 1 3 4]
I am looking for a way to shuffle the order of those elements that have the same value in image, so that I do not always obtain the indexes in a crescendum but they are mixed, so for example in this case:
index_sorted = [2 1 3 4; 4 1 2 3; 2 1 3 4; 2 3 1 4]
or something like that.
Do you know a way to do it? Note that image is a large matrix and its elements can vary in R, as well as it can have as many repeated values as possible.
Thank you so so much for your help!!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!