How to replace minimum values in the vector with 1 and replace others value plus one
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
the cyclist
2022-3-27
This might be too specific to your example, but a much simpler transform that gets what you want is
A = [2; 1; 4; 1; 3; 3; 1; 1];
result = max(A) + 1 - A
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!