How can I replace this a value in the array with the k where the value is k-th min?

1 回表示 (過去 30 日間)
Han
Han 2019 年 7 月 2 日
コメント済み: Han 2019 年 7 月 2 日
I wanted to elaborate on the title, but it's not easy, so I'll explain it with the following example.
For example, there is [1 434 22 434 23 53 89 199]
I want to change it to [1 7 2 7 3 4 5 6]
434 is 7th min value. 22 is 2nd min value.
I want to know what i th min value of the each value is, and it insert to the matrix.
  2 件のコメント
Shameer Parmar
Shameer Parmar 2019 年 7 月 2 日
what is mean by "434 is 7th min value. 22 is 2nd min value." How you calculated this ?
Shameer Parmar
Shameer Parmar 2019 年 7 月 2 日
Here you go..
A = [1 434 22 434 23 53 89 199];
newVector = [];
for i=1:length(A)
minimum = find(ismember(unique(A),A(i)));
newVector = [newVector, minimum];
end

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2019 年 7 月 2 日
This is the simplest:
v = [1 434 22 434 23 53 89 199]
[~, ~, newv] = unique(v)

その他の回答 (1 件)

Chirag Nighut
Chirag Nighut 2019 年 7 月 2 日
A = [1 434 22 434 23 53 89 199];
u = unique(A)
for i=1:1:length(A)
A(find(A==u(i))) = i;
end

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by