Find the minimums along 3rd dimension of an array

21 ビュー (過去 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 Center および File ExchangeCreating 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