Reputation: 109
Maybe the question is a little bit confused, I'll make an example below.
Let's say I have a 3 matrices a
, b
, c
with same size.
a = [2, 5; 6, 9];
b = [3, 3; 8, 1];
c = [5, 5; 2, 7];
How can I get the new matrix max
with each max element in all three matrices?
max = [5, 5; 8, 9]
I know I could create logical matrix like a>b
and then do the math, calc it out, is there any other more efficient way to do it?
Upvotes: 1
Views: 55
Reputation: 1481
You can concatenate the matrices into one 2x2x3
matrix using
d=cat(3,a,b,c)
and then use max
-function to get your desired output:
maxValues=max(d,[],3)
The 3rd input to max
defines along which dimension of the first input you want to find the maximum value.
Upvotes: 3