Hello all ,
I am working with data arranged in a large 3D matrix and am wondering how I might find the maximum value in the Z direction of all elements at a specific x,y coordinate.
For example, if:
A = [1 2 3; 4 7 8]
B = [6 4 2; 3 5 7]
C = [3 3 9; 2 3 2]
and i arrange the matrix as such:
data_3d = cat(3, A, B, C)
I would like to find the maximum value of all 'z' elements positioned at the x,y coordinates(1,1) compared to each other, where: max_1 = 6
Is there a simple function to do this, or is it necessary to call each individual element in the following manner:
max_1 = max([A(1,1) B(1,1) C(1,1)])
(will this ^ even work?)
A bit of a matlab newbie, and any help is greatly appreciated. :) Thank you for your time

 Akzeptierte Antwort

Star Strider
Star Strider am 7 Aug. 2016

4 Stimmen

Try this:
max_data_3d = max(data_3d, [], 3)
max_data_3d =
6 4 9
4 7 8

4 Kommentare

lunalara
lunalara am 7 Aug. 2016
Thank you for your quick response, Star!
That is great! I am wondering though, is there a way to alter this and just request a single maximum? say if i just want '6' as my answer for maximum of elements at x,y (1,1)?
Star Strider
Star Strider am 7 Aug. 2016
Bearbeitet: Star Strider am 7 Aug. 2016
My pleasure!
The easiest way to do that would be:
max_data_3d = max(data_3d, [], 3);
xy_1_1 = max_data_3d(1,1)
xy_1_1 =
6
The MATLAB code is optimised, so getting the maximum of the entire matrix along the third dimension and then just referencing the one you want is likely easiest and most efficient.
You can also do:
xy(1,1) = max_data_3d(1,1)
xy =
6
if you want, but I don’t see any particular advantage to that approach.
Experiment with the code to see what works best for you.
EDIT — You can get the maximum of only the (1,1) position in the concatenated matrix directly if you want:
xy11 = max(data_3d(1,1,:))
xy11 =
6
lunalara
lunalara am 8 Aug. 2016
Star, you have made my day.
It would probably be much easier to get the full maximum beforehand, then just pick and choose which values are important from the resulting matrix like you said.
Thank you so much for your help!!
Star Strider
Star Strider am 8 Aug. 2016
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Fathia Mohammed
Fathia Mohammed am 17 Feb. 2021

1 Stimme

max(A,[],3)

1 Kommentar

Rik
Rik am 17 Feb. 2021
How is this different from what Star Strider posted?

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 7 Aug. 2016

Kommentiert:

Rik
am 17 Feb. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by