Multiple Maximas in multiple matrices

Hello,
I want to get multiple maximas of multiple matrices.
I got a solution to get the maxValue but it gives me one absolute max Value.
I want a output like this for this example:
max Value = [15 25 35]
% data
matrix1=[10:1:15];
matrix2=[15:1:25];
matrix3=[25:1:35];
%max
maxValue = max([matrix1(:);matrix2(:);matrix3(:)])
maxValue = 35

1 件のコメント

Jan
Jan 2022 年 6 月 14 日
Hint: [] is the operator for a concatenation of arrays. 10:1:15 is a vector and [10:1:15] concatenates it with nothing. So this is a waste of time only.

サインインしてコメントする。

 採用された回答

Voss
Voss 2022 年 6 月 14 日

1 投票

% data
matrix1=[10:1:15];
matrix2=[15:1:25];
matrix3=[25:1:35];
%max
maxValue = cellfun(@max,{matrix1 matrix2 matrix3})
maxValue = 1×3
15 25 35

3 件のコメント

Eren Atar
Eren Atar 2022 年 6 月 14 日
Thank you :)
Image Analyst
Image Analyst 2022 年 6 月 14 日
What? Really? Why are you messing with the complication and inefficiencies of cell arrays when a simple solution like I gave works fine? Personally I would not use this method because I try to avoid cell arrays unless absolutely necessary. Beginners especially have a hard time trying to figure out when to use parentheses and when to use braces when dealing with cell arrays.
Voss
Voss 2022 年 6 月 14 日
@Eren Atar You're welcome!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 6 月 14 日

2 投票

Try it this way, with max() inside the brackets:
% data
matrix1=[10:1:15];
matrix2=[15:1:25];
matrix3=[25:1:35];
%max
maxValue = [max(matrix1(:)); max(matrix2(:)); max(matrix3(:))]
maxValue = 3×1
15 25 35

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

リリース

R2020b

質問済み:

2022 年 6 月 14 日

コメント済み:

2022 年 6 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by