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

조회 수: 1 (최근 30일)
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?

채택된 답변

Roger Stafford
Roger Stafford 2014년 3월 19일
[~,~,Fnew] = unique(F(:));
Fnew = reshape(Fnew,size(F));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Portfolio Optimization and Asset Allocation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by