Zero-filling matricies but different dimensions
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!