Count number of matrix elements in a given vector

Background: Need to count the number of correct elements in a series of ranked lists.
I have a matrix where with j columns and 30 rows. Each column has the numbers 1:30 in random order. I have a vector "actual" with the numbers 1:30 in the correct order.
For each of the columns, how do I count the number of each columns elements that are in the correct place?

 Accepted Answer

M = 30 x j matrix of random ordered numbers 1:30
C = 30 x 1 "correct" ordering of 1:30
N = sum(bsxfun(@eq,M,C)); % Number of correct element spots in each column

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!