フィルターのクリア

Multidimensional Array deleting entire max record keeping information across in order

2 ビュー (過去 30 日間)
IDN
IDN 2021 年 12 月 22 日
コメント済み: IDN 2021 年 12 月 25 日
I have the following loop:
sz = 20;
m = zeros(size(sz));
for i = 1:sz
[max_val, position] = max(sh(:)); %Find Max Position
m(i,:) = [position]; %Store Max Position in "m"
sh(sh==max(sh)) = []; %Delete current max value of "sh"
end
What I am trying to do here is pretty much to extract to "m" the top 20 highest values in "sh" (sh is a 3D matrix - 100x60x95). What i am not sure is happening is if " sh(sh==max(sh)) = []; " deletes only the value or the entire "row" containig the data of the max value.
What i ultimately need is once i delete the value, i need to delete everything else pertaining to that value in the matrix so when values shift they keep their order. Thanks so much for the help!
  3 件のコメント
IDN
IDN 2021 年 12 月 23 日
Thanks so much this is actually great as I am just starting to learn matlab. So "sh" is the result of a 3 variables x1,x2,x3 computation. Therefore, what I am really after is the top 10 values of sh and their respective coefficients. I have not been able to find a way to do this...so I figured if I delete the max and its row of coefficients and do this 10 times I would get the top 10 max sh values and their respective coefficients.
IDN
IDN 2021 年 12 月 24 日
Ah sorry I forgot to tell you I was checking top 10 unique sh...

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

採用された回答

Voss
Voss 2021 年 12 月 23 日
If all you need is the 20 maximum values and their positions (either linear index or subscript index), then you can do this:
sh_temp = sh;
sh_temp(isnan(sh_temp)) = -Inf;
[sh_sort,ii] = sort(sh_temp(:),'descend');
sz = 20;
max_vals = sh_sort(1:sz);
m = ii(1:sz); % linear index of max_vals
[r,c,p] = ind2sub(size(sh),m); % row, column, 'page' index for each of max_vals
  12 件のコメント
Voss
Voss 2021 年 12 月 24 日
Ah, ok. So everything looks good, right?
IDN
IDN 2021 年 12 月 25 日
Yes, thanks so much!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by