Thread Subject: sort function IDX when sorting on both dimensions

Subject: sort function IDX when sorting on both dimensions

From: Manal

Date: 16 Nov, 2009 06:58:03

Message: 1 of 1

Hi

I have a distance matrix of numeric values, and data labels on an array of cells. I want to sort the distance matrix on both dimensions, so that the smallest values are all on the left top corner of the distance matrix, and the highest values are all on the right bottom corner. I still need to use the indices return to find the sorted permutation of the labels. I was thinking that the following code should do it:

upTriangle = triu(distMatrix);
[DistMatSorted,IX] = sort(upTriangle, 2);
for j=1:m
    for i=1:n
         DistMatSorted(i,j) = DistMatSorted(j,i);
    end
        DistMatLabelsSorted(j) = DistMatLabels(IX(1, j));
 end

but I didn't receive the right sorting, but I received the right permutations of indices with the new sorting. The sorting that I am looking for is achieved using dim = 1 in the sorting function input:

[DistMatSorted,IX] = sort(upTriangle, 1);

However, the labels perumtations are messed up, with repeatitions and of course missing labels.

I do not know how to correlate the sort help function to the data organization that I have (i.e. having the labels in a one dimensional array while sorting a matrix, the help is focused on finding the permutations of the matrix itself, and not a related vector),

Am I making myself clear? I really need help in this function, lots of problems are based on the wrong sorting of the labels with the distance matrix,

thank you very much in advance,

Kind Regads,

Manal

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com