How to I find the maximum value of corresponding e

2019-07-07 01:12发布

问题:

I have four matrices with the same dimensions, let's say:

A = 
    1 2 5
    4 2 9

B =
    4 5 9
    8 0 1

C =
    5 3 9
    0 4 0

D =
    5 9 1
    0 9 3

How do I find the maximum value of all corresponding elements in the four matrices? In my example, the result should be as follows:

maxABCD =
    5 9 9
    8 9 9

Thank you...

回答1:

Try concatenating all four matrices along the 3rd dimension and then invoke max:

maxABCD = max(cat(3, A, B, C, D), [], 3)


回答2:

Or the following should work as well:

>> max(A,max(B,max(C,D)))
ans =

   5   9   9
   8   9   9