MATLAB: Classification of a matrix to 0 and 1 matrix

accumarrayarraymatrixnumel

Hello everyone,
I want matrix A to be like matrix B
ID, age and sex groups are repeated in matrix A. Matrix B is classified age based on the sex group with counting the value from matrix A. if any value in any group was repeated more than 1, then total will appear in matrix B. For example, in matrix A: ID=5, Age group=2, Sex group=2—>Then in matrix B: the value (4,5) is equal by 2

Best Answer

Assuming A and B are numerical arrays arranged as shown in your diagram,
B = accumarray([2*A(:,2)+A(:,3)-2,A(:,1)],1,[2*max(A(:,2)),max(A(:,1))]);