MATLAB: Compare the elements of multiple matrix and return min and max matrix

matrix array min max

Hi everyone, I want to compare the matrixes A, B, C and find the min and max values for the same index;
A = [1 92 33;
4 15 66;
16 27 48]
B = [34 45 16;
67 38 19;
2 83 31]
C = [20 53 61;
4 17 83;
35 14 39]
and return to two matrixes such as,
Min = [1 45 16;
4 15 19;
2 14 31]
Max = [34 92 61;
67 88 83;
35 83 48]
How can I get this result? Could you please help with this?

Best Answer

  • First concatenate them, then do the min and max calls:
    ABC = cat(3,A,B,C);
    Min = min(ABC,[],3)
    Max= max(ABC,[],3)
    producing:
    Min =
    1 45 16
    4 15 19
    2 14 31
    Max =
    34 92 61
    67 38 83
    35 83 48