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 I wanna again compare A and B1 (Like B) is 10x1 matrix too ? Perhaps i will add B2, B3..and so on. plz help me. Thanks! Regards, Kyaw Kyaw

 Accepted Answer

A=[1 2 3;4 5 6;7 8 9;1 0 1]
B=[1 3 2]
C=bsxfun(@eq,a,b)
For floating point numbers look at Analyst link

4 Comments

Thanks! What function can i use in this case if I wanna again compare A and B1 (Like B) ? Perhaps i will add B2, B3..and so on....
eg: B1=[3 2 1], B3=[4 2 1]
Use the same function. What is the problem with that?
Or use
a=[1 2 3;4 5 6;7 8 9;1 0 1]
b=[1 3 2;4 2 1]
[n,m]=size(b)
c=reshape(b',1,m,n)
out=bsxfun(@eq,a,c)

Sign in to comment.

More Answers (0)

Asked:

on 13 Apr 2014

Commented:

on 14 Apr 2014

Community Treasure Hunt

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

Start Hunting!