フィルターのクリア

Zero-filling matricies but different dimensions

1 回表示 (過去 30 日間)
Bran
Bran 2013 年 2 月 5 日
Hi there,
I have two matricies A = [1 2 3; 4 5 6; 6 7 8; 11 12 13] and B = [1 2 3; 4 5 6; 11 12 13] and I would like to create a new matrix c which would be C = [1 2 3; 4 5 6; 0 0 0; 11 12 13]
I thought the following script would do it;
for i = 1:size(A); j = 1:size(B); k = 1:size(A); if B(j,:) == A(i,:); C(k,:) = B(j,:);
i = i + 1; j = j + 1; k = k + 1; else C(k,:) = [0 0 0];
i = i; j = j + 1; end end end
However, because the matricies do not have the same dimensions this is causing the computer a problem. Any ideas on what I can do with this?

採用された回答

Sven
Sven 2013 年 2 月 5 日
Hi Bran,
I think this is what you're trying to do:
A = [1 2 3; 4 5 6; 6 7 8; 11 12 13]
B = [1 2 3; 4 5 6; 11 12 13]
C = A;
C(~ismember(A,B,'rows'),:) = 0
Does that work for you?
Sven.
  1 件のコメント
Bran
Bran 2013 年 2 月 6 日
Yes fantastic! Thanks Sven! :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by