Find the minimums along 3rd dimension of an array

10 visualizaciones (últimos 30 días)
Bill Tubbs
Bill Tubbs el 9 de Dic. de 2021
Editada: Bill Tubbs el 10 de Dic. de 2021
I have a 3d array that is constructed from two 2d arrays:
a = [1 2 3; 4 5 6; 7 8 9];
b = [1 2 0; 4 0 9; 9 8 9];
c = cat(3,a,b);
I want to find the minimums along dimension 3 only.
Desired output:
c_mins =
1 2 0
4 0 6
7 8 9
I thought this would work but it seems to give a different result which I don't understant:
min(c, 3)
ans(:,:,1) =
1 2 3
3 3 3
3 3 3
ans(:,:,2) =
1 2 0
3 0 3
3 3 3

Respuesta aceptada

Image Analyst
Image Analyst el 9 de Dic. de 2021
You need [] in min():
a = [1 2 3; 4 5 6; 7 8 9];
b = [1 2 0; 4 0 9; 9 8 9];
c = cat(3,a,b)
c =
c(:,:,1) = 1 2 3 4 5 6 7 8 9 c(:,:,2) = 1 2 0 4 0 9 9 8 9
minValues = min(c, [], 3)
minValues = 3×3
1 2 0 4 0 6 7 8 9
  3 comentarios
Image Analyst
Image Analyst el 10 de Dic. de 2021
@Bill Tubbs, yeah, sometimes there are inconsistencies like that.
Steven Lord
Steven Lord el 10 de Dic. de 2021
If I recall correctly the syntax min(A, B) predates the introduction of 3-dimensional arrays into MATLAB (both of which predate the start of my tenure at MathWorks.) We don't want min(A, scalar) to be ambiguous if the scalar is a potential dimension number so we instead treat it always as B.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by