I have a Matrix called A as below
[1 1 3;1 2 2;1 3 3;2 1 1;2 2 3;2 3 2;2 4 4]
I want to produce a column vector that counts the number of times a value occurs in the 2nd column, I have tried the following function :
function count_stars(A)total = 0;for i = 1:size(A,1) total = total + (A(i,2)==A(:,2)); endtotal
This counts the number of matching values in the entire column e.g.
2 2 2 2 2 2 1
What I am wanting is to match to values between 1:i only rather than the entire column so that the output looks like this
1112221
Any insights you are able to share are greatly appreciated!
Best Answer