Replacing all the elements of one matrix with new values (one to one mapping)

3 views (last 30 days)
I have a large matrix of size 50000×3. I would like to replace the values of the elements with a new values. To illustrate my problem, for example, let's say F is as follows.
F = [22 60 100;
11 13 14;
10 12 15;
16 15 17;
17 18 25;
13 19 20;
20 30 22;
10 11 12]
unique(F)' = 10 11 12 13 14 15 16 17 18 19 20 22 25 30 60 100
Now I want to assign new values to each element of F. The assignment is such that the lowest value of F maps to 1, the second lowest value maps to 2. It continues with an increment of 1 until it reaches the highest value in F. In the example above, I want to assign 1 to 10, 2 to 11, ..., and 16 to 100 and construct a new F as follows:
Fnew = [12 15 16;
2 4 5;
1 3 6;
7 6 8;
8 9 13;
13 10 11;
11 14 12;
1 2 3]
unique(Fnew)' = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Could someone instruct me how to construct such a matrix from F?

Accepted Answer

Roger Stafford
Roger Stafford on 19 Mar 2014
[~,~,Fnew] = unique(F(:));
Fnew = reshape(Fnew,size(F));

More Answers (0)

Categories

Find more on Matrices and Arrays 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!