Display matrix values?

So, I have a large matrix (4091252x2) that looks something like this:

439105 1053224 439105 1696241 439105 580064 439105 1464748 1836139 1593258 1464748 439105 1464748 1053224 1464748 1696241 1464748 580064 580064 439105 

Basically, the matrix represents calls made from one person to another, represented by personID (439105 calls 1053224). What I want to do is reduce the scale of this matrix so that the smallest personID = 1 and 2 for the next lower identifier person, 3 for the next lower identifier personID after this, etc. For example, if the matrix looked like this:

 110 503 402 110 300 900 300 402 402 110 

I would like it to display:

 1 4 3 1 2 5 2 3 3 1 

The problem is that I am new to Matlab and I have no idea how to do this. I looked through reshape and sub2ind , but I really don't think this is what I am in search of. How to do it in Matlab?

Any help would be greatly appreciated, thanks!

+7
mapping matrix matlab
source share
2 answers

You can use the third unique output for this purpose, you just need to change the form.

 A=[110 503 402 110 300 900 300 402] [~,~,D]=unique(A); reshape(D,size(A)) 
+7
source share

For such a task, the unique function is your friend. Enter help unique for more information.

For this problem, if you have input:

 input = [[110 503]; [402 110]; [300 900]; [300 402]; [402 110]]; 

You can get the required mapping as follows:

 output = input; [C,IA,IC] = unique(input(:)); output(:) = IC; 

Which will give the desired result:

 output = 1 4 3 1 2 5 2 3 3 1 

IC contains indices ("I" in "IC"), so they will be values ​​from 1 to the number of unique values ​​in your input array. If you want to use other tokens, you can use IC to index into another array of unique identifiers.

FYI, on my Macbook Pro, it takes about 1.2 seconds to complete this operation on the 4091252x2 array.

+6
source share

All Articles