フィルターのクリア

one-by-one matrix assignment

1 回表示 (過去 30 日間)
Antonio
Antonio 2018 年 2 月 6 日
コメント済み: Antonio 2018 年 2 月 6 日
I need to find the minimum values in each column of matrix "A", and then replace those min values with the values in last row of matrix "B" (which has same number of columns). Like I have these:
>> A = randi(10,10,5)
A =
3 5 9 5 8
7 6 4 10 2
8 4 1 7 4
4 7 2 8 2
7 5 8 7 5
3 7 10 10 1
5 7 8 5 7
8 3 8 2 3
6 10 2 1 10
3 7 6 7 2
>> B = randi(100,3,5)
B =
10 34 66 18 62
99 95 49 54 81
52 1 52 9 95
>> [M,I] = min(A)
M =
3 3 1 1 1
I =
1 8 3 9 6
And I want to replace the values of "M" with "B(end,:), so that:
A(1,1) = B(end,1);
A(8,2) = B(end,2);
A(3,3) = B(end,3);
A(9,4) = B(end,4);
A(6,5) = B(end,5);
I try "A(I) = B(end,:)" and "A(I(1,:)) = B(end,:)" but they do not work! Any ideas how I could do that? My real matrices are huge (1200x100000) so no way to do it by hand!
  4 件のコメント
Jos (10584)
Jos (10584) 2018 年 2 月 6 日
ok. then Andrei's answer suffices.
Antonio
Antonio 2018 年 2 月 6 日
@Jos (10584) great, thanks!

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2018 年 2 月 6 日
編集済み: Andrei Bobrov 2018 年 2 月 6 日
[~,idx] = min(A);
s = size(A);
A(sub2ind(s,idx,1:s(2))) = B(end,:);

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by