Find the minimums along 3rd dimension of an array

8 次查看(过去 30 天)
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 个评论
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 中查找有关 Matrices and Arrays 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by