映射矩阵与另一个矩阵 [英] map a matrix with another matrix
本文介绍了映射矩阵与另一个矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不得不矩阵与只包含1和0另一个矩阵映射的问题。
在这里,我的问题的例子: A
是双打矩阵
A = [1 4 3;
2 3 4;
4 3 1;
4 5 5;
1 2 1];
B是用一和零的矩阵
B = [0 0 0;
0 0 0;
1 1 1;
1 1 1;
0 0 0];
我要实现矩阵 C
这是结果 A
按映射乙
,就像这样:
C = [0 0 0;
0 0 0;
4 3 1;
4 5 5;
0 0 0];
我试过 B
作为逻辑阵列和矩阵。两者导致了同样的错误:
下标指标必须是真正的正整数或逻辑值。
块引用>解决方案只需乘A和B元素明智的:
C = A. * B
I have a question to the mapping of a matrix with another matrix which contains only 1 and 0. Here an example of my problem:
A
is the matrix with doublesA = [ 1 4 3; 2 3 4; 4 3 1; 4 5 5; 1 2 1];
B is a matrix with ones and zeros:
B = [ 0 0 0; 0 0 0; 1 1 1; 1 1 1; 0 0 0];
I want to achieve a matrix
C
which is the result ofA
mapped byB
, just like that:C = [ 0 0 0; 0 0 0; 4 3 1; 4 5 5; 0 0 0];
I tried
B
as a logical array and as a matrix. Both lead to the same error:"Subscript indices must either be real positive integers or logicals."
解决方案Just multiply A and B element-wise:
C = A.*B
这篇关于映射矩阵与另一个矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文