compare multiple matrices matlab

compare, matlab, matrix

Solution

If the three matrices are A, B, C, do this:

[~, M] = max(cat(3,A,B,C),[],3);

It creates a 3D "matrix" and maximizes across the third dimension.

Problem

I have multiple matrices of the same size and want to compare them. As a result I need a matrix which gives me the biggest of the 3 for every value. I will clarify what i mean with an example: I have 3 matrices with data of 3 persons. I would like to compare these 3 and get a matrix as result. In that matrix every cell/value should be the name of the matrix who had the highest value for that cell. So if in the 3 matrices the first value (1 colum, 1 row) is accordingly `2, 5, 8` the first value of the result matrix should be `3` (or the name of the 3 matrix).

Original source