Cell by cell evaluation across dimensions

I'll start with I'm brand new to MATLAB, with only about 10 hours of trainging with it. It seems like as soon as I get close to an answer in a training document or video, it stops with the topic and moves on to something else.
If create 4, 3x3 arrays of random numbers using : data = rand(3,3,4)
I get:
data(:,:,1) =
0.6312 0.2242 0.3872
0.3551 0.6525 0.1422
0.9970 0.6050 0.0251
data(:,:,2) =
0.4211 0.3704 0.5710
0.1841 0.8416 0.1769
0.7258 0.7342 0.9574
data(:,:,3) =
0.2653 0.3736 0.1806
0.9246 0.0875 0.0451
0.2238 0.6401 0.7232
data(:,:,4) =
0.3474 0.6273 0.8006
0.6606 0.0216 0.7458
0.3839 0.9106 0.8131
I'm trying to find the highest value of a cell across all for pages so the end result would be something like
Result =
0.6312 0.6273 0.8006
0.9246 0.8416 0.7458
0.9970 0.9106 0.9574
I've been trying to use the max function, but I can't seem to get it to go the right way. I'm fine across row's and columes but not for a cell going though pages.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 26 de Jun. de 2020
max(data, [], 3)

3 comentarios

Micheal Peters
Micheal Peters el 2 de Jul. de 2020
Thank you for the answer. I would say that seems to easy, but that just seems to be the case with this software. I need to go back into the manual and see what that 3 is for, and unless you have time to explain?
Walter Roberson
Walter Roberson el 2 de Jul. de 2020
max() and min() have a calling sequence that is slightly different than most functions.
max(A) would be the maximum of A along the first non-singular dimension.
max(A,B) when B is not empty, would be the maximum of corresponding elements of A and B, so max([A(J,K), B(J,K)]) for each J,K . So max(A,3) would be the maximum of the number 3 or the contents of A
max(A,B,d) is an error if B is not empty. When B is empty, the maximum of A is taken along the dimension indicated by d. So max(A,[],3) means the maximum along dimension #3.
This is a bit different than functions such as median, where the dimension number is the second argument, median(A,3) is median along dimension #3. But watch out for std(): std(A,3) would use 3 as the weight vector, and the dimension number needs to go third, std(A,[],3)
Micheal Peters
Micheal Peters el 5 de Jul. de 2020
Thank you for the answer and the explination

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 26 de Jun. de 2020

Comentada:

el 5 de Jul. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by