MATLAB: Finding out the number of times a specific row appears in a large Matrix.

matrix manipulationrow

The last part of a script I am writing is to use a large .dat file(B), basically a matrix of 100,000 rows of 6 numbers each. I must then use a single row of 6 numbers(A) and I must find out how many times A appears completely in B. I have been searching for an answer and I am stumped, any help appreciated.

Best Answer

How about setdiff() with the 'rows' option specified.
x = randi(10,10,6);
y = x(3,:);
x(1,:) = y;
[C,Ix] = setdiff(x,y,'rows');
size(x,1)-numel(Ix) % gives how many times the row appears