フィルターのクリア

Specifying values in 2D array when I know the indices

2 ビュー (過去 30 日間)
MichailM
MichailM 2022 年 11 月 30 日
コメント済み: MichailM 2022 年 11 月 30 日
I have the short example below. With the max function I find the indices of the maximum values whithin each column of array A. I want an array C which will include the values of array B by using the idx values I specified before. So, C will be C = [1 2 3 4 5]. How can I do that without a for-loop?
A = [1 1 1 1 100;
100 1 1 1 1
1 1 100 1 1
1 1 1 100 1;
1 100 1 1 1];
[~,idx] = max(A,[],1);
B = [1 1 1 1 5;
1 1 1 1 1
1 1 3 1 1
1 1 1 4 1;
1 2 1 1 1];

採用された回答

Fangjun Jiang
Fangjun Jiang 2022 年 11 月 30 日
A = [1 1 1 1 100;
100 1 1 1 1
1 1 100 1 1
1 1 1 100 1;
1 100 1 1 1];
[~,idx] = max(A,[],1,'linear')
idx = 1×5
2 10 13 19 21
B = [1 1 1 1 5;
1 1 1 1 1
1 1 3 1 1
1 1 1 4 1;
1 2 1 1 1];
C=B(idx)
C = 1×5
1 2 3 4 5

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming Utilities についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by