How to find the maximum value and its index from matrices?

8 views (last 30 days)
I have a multi dimensional matrix
m(:,:,1) = [1 2 3 4; 8 -21 23 2; 3 1 3 7; 42 43 12 4]
m(:,:,2) = [23 34 1 5;2 -6 3 -7; 2 -65 2 2; 5 8 52 -1]
m(:,:,3) = [54 1 6 2; 51 -4 1 6; 5 1 7 1; 65 1 57 65]
max = [54 34 6 5; 51 -4 23 6; 5 1 7 7; 65 43 57 65]
index =[3 2 3 2; 3 3 1 3; 3 1 3 1; 3 1 3 3]
max should have the maximum value out of the given matrices. index should indicate which matrix the max value came from.
thanks for your help in advance :)

Accepted Answer

the cyclist
the cyclist on 31 Jul 2016
[max_m,idx_m] = max(m,[],3)

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!