How to replace minimum values in the vector with 1 and replace others value plus one
Show older comments
I have a vector A
A = [2; 1; 4; 1; 3; 3; 1; 1];
In this vector I want to find maximum and put the value to 1
[B,I] = sort(A,'descend') ;
B = [4; 3; 3; 2; 1; 1; 1; 1]
B new_B
----------------
4 ---> 1
For other values, we should have previous value+1
B new_B
---------------
4 ---> 1
3 ---> 1+1=2= previous value+1
3 ---> 1+1=2
2 ---> 2+1=3= previous value+1
1 ---> 3+1=4= previous value+1
1 ---> 3+1=4
1 ---> 3+1=4
1 ---> 3+1=4
If we consider vector A the result should be:
result = [3; 4; 1; 4; 2; 2; 4 ; 4]
2--->3 2 should replace with 3
1--->4 1 should replace with 4
4--->1 4 should replace with 1
Accepted Answer
More Answers (0)
Categories
Find more on Structures 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!