Combining matrix value with its previous value

5 views (last 30 days)
Hello all.. I use c=bsxfun(@eq,b,a) to compare value of two matrix. but i difficult to count unmatch value. for example i use this code
a = [1 2 3 4 7 6; 3 2 4 6 7 2 ];
b = [1 3 2 4 5 7; 3 4 5 6 7 2; 2 3 4 5 6 6];
for i = 1:size(a,1)
c= bsxfun(@eq,a(i,:),b)
match = sum(c')
end
and result
c =
1 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
match =
2 1 1
c =
0 0 0 0 0 0
1 0 0 1 1 1
0 0 1 0 0 0
match =
0 4 1
I want to save value first match matrix with second match. for example
total_match =
2 5 2
Do you have any suggestion ? thanks..

Accepted Answer

Matt J
Matt J on 24 Mar 2013
N=size(a,2);
a=reshape(a.',N,1,[]);
b=b.';
c=bsxfun(@eq,a,b);
total_match=sum(sum(c,1),3);

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!