简体   繁体   English

Matlab中不同尺寸维度的矩阵元素的比较

[英]Comparing elements of matrix of different Sizes dimension in Matlab

Can anybody help me to find out the method to compare the elements of different sized matrix in Matlab ? 有人可以帮助我找出比较Matlab中不同大小矩阵元素的方法吗?

I have one matrix A (100×10) with random elements. 我有一个随机元素的矩阵A (100×10)。

The second array has some of elements which are in matrix B (1×10) with random elements. 第二个数组的某些元素位于矩阵B (1×10)中,具有随机元素。

Let's say element of matrix A(i,j) and B(i,j) is element of B . 假设矩阵A(i,j)元素和B(i,j)B元素。

So I want to compare B(i_1,j_1) is equal A(i_1,j_1; i_2,j_1; i_3,j_1;.....; i_100_j_1) in these two matrices, ie, we need to compare first row, first column of matrix B and all row, first column of matrix A . 所以我想在这两个矩阵中比较B(i_1,j_1)等于A(i_1,j_1; i_2,j_1; i_3,j_1;.....; i_100_j_1) ,即我们需要比较第一行,第一行矩阵B一列以及矩阵A所有第一行。

If they are equal - 1 , if not equal - 0 . 如果它们等于1 ,如果不等于0 And they will be new matrix C . 它们将是新矩阵C

The elements are numbers not strings. 元素是数字而不是字符串。

What function can i use in this case if wanna again compare A and B1 (Like B) is 10x1 matrix too ? 如果要再次比较A和B1(如B)也是10x1矩阵,在这种情况下可以使用什么功能? Perhaps i will add B2, B3..and so on. 也许我会添加B2,B3 ..等等。 plz help me. 请帮助我。

Regards, Kyaw Kyaw 此致Kyaw Kyaw

听起来像bsxfun的情况:

C = bsxfun(@eq, A,B);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM