## How can i find maximum value at each (x,y)location and the plane which contains it in a multidimensional matrix

### ipwork (view profile)

on 24 Aug 2019 at 12:41
Latest activity Commented on by Star Strider

### Star Strider (view profile)

on 24 Aug 2019 at 16:31
Accepted Answer by Star Strider

### Star Strider (view profile)

I have multiple matrices of (M by N) sizes. I need to find which among them contains maximum value at each location(x,y). For loop is very time consumming. Need vectorized operation. Using Matlab 2016 version. Thanks.

### Tags ### Star Strider (view profile)

Answer by Star Strider

### Star Strider (view profile)

on 24 Aug 2019 at 13:20

Try this:
M = 10;
N = 15;
A1 = rand(M,N); % Create Matrix
A2 = rand(M,N); % Create Matrix
A3 = rand(M,N); % Create Matrix
A4 = rand(M,N); % Create Matrix
Acat = cat(3, A1, A2, A3, A4); % Concatenate Along Dimension 3
[Max,MaxIdx] = max(Acat, [], 3); % Find Max & inIndex Along Dimension 3
The ‘Max’ value is the value of the maximum amongst the matrices created y ‘Acat’, and ‘MaxIdx’ is the matrix with that value, correspoinding to the order in which you concatenated them.

ipwork

### ipwork (view profile)

on 24 Aug 2019 at 16:22
Great, such a simple and efficient solution! Thanks!
Star Strider

### Star Strider (view profile)

on 24 Aug 2019 at 16:31
As always, my pleasure!