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!