Get the coordinate maximum of 3 matrices in MATLAB

Suppose I have 3 matrix A , Bed and , the C . I want to create a new matrix that will contain the maximum value of the matrices.

For example, let

A = [ a11 a12.. ] B = [b11 b12 ..] C = [c11 c12 ..]
    [ a21 a22.. ]     [b21 b22 ..]     [c21 c22 ..]

I want the new matrix to be constructed this way

NewMatr = [max(a11,b11,c11) max(a12,b12,c12) .. ]
          [max(a21,b21,c21) max(a22,b22,c22) .. ]

I was thinking of combining them into a new matrix that will contain 3x1 vectors and apply max to this new matrix, but I don't know how to do this. A Pf course always exists for a method, but I am doing the optimization.

+4
source share
2 answers

In addition to concatenation, you can use the 2-input version maxtwice:

max(max(A,B),C)

max :

C = max(A,B) , A B , A B. A B , .

+2

dim ( cat), dim ( max):

NewMatr = max(cat(3,A,B,C),[],3);
+1

Source: https://habr.com/ru/post/1529505/


All Articles