필터 지우기
필터 지우기

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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by