Find the minimums along 3rd dimension of an array

조회 수: 12 (최근 30일)
Bill Tubbs
Bill Tubbs 2021년 12월 9일
편집: Bill Tubbs 2021년 12월 10일
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

채택된 답변

Image Analyst
Image Analyst 2021년 12월 9일
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
Image Analyst
Image Analyst 2021년 12월 10일
@Bill Tubbs, yeah, sometimes there are inconsistencies like that.
Steven Lord
Steven Lord 2021년 12월 10일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by