user3455066
user3455066

Reputation: 87

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 ?

I have one matrix A (100×10) with random elements.

The second array has some of elements which are in matrix B (1×10) with random elements.

Let's say element of matrix A(i,j) and B(i,j) is element of 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, i.e, we need to compare first row, first column of matrix B and all row, first column of matrix A.

If they are equal - 1, if not equal - 0. And they will be new matrix 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 ? Perhaps i will add B2, B3..and so on. plz help me.

Regards, Kyaw Kyaw

Upvotes: 1

Views: 1120

Answers (1)

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38032

Sounds like a case for bsxfun:

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

Upvotes: 2

Related Questions