Find the minimums along 3rd dimension of an array

9 Ansichten (letzte 30 Tage)
Bill Tubbs
Bill Tubbs am 9 Dez. 2021
Bearbeitet: Bill Tubbs am 10 Dez. 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

Akzeptierte Antwort

Image Analyst
Image Analyst am 9 Dez. 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 Kommentare
Image Analyst
Image Analyst am 10 Dez. 2021
@Bill Tubbs, yeah, sometimes there are inconsistencies like that.
Steven Lord
Steven Lord am 10 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by