max value of N arrays

2 ビュー (過去 30 日間)
simone zappalà
simone zappalà 2022 年 5 月 25 日
回答済み: Voss 2022 年 5 月 25 日
I've several arrays, all are 130 rows and 1 column with different numbers created from a for cycle, so every row is the result of a for cycle i=1:130. I want to know how i can take the max value between these arrays for every cycle. At the end i need an array with 130 rows and one column each row is the max value between all the arrays.
example
x=[1,3,6,9]
y=[2,4,5,8]
max(x,y)=[2,4,6,9]

採用された回答

Voss
Voss 2022 年 5 月 25 日
You say they're column vectors in the description, but the example uses row vectors. It doesn't really matter, you can do it either way:
x=[1,3,6,9]; % row vectors given
y=[2,4,5,8];
z=[0,5,1,2];
max([x;y;z],[],1) % row vector result
ans = 1×4
2 5 6 9
x=[1;3;6;9]; % column vectors given
y=[2;4;5;8];
z=[0;5;1;2];
max([x y z],[],2) % column vector result
ans = 4×1
2 5 6 9

その他の回答 (1 件)

MJFcoNaN
MJFcoNaN 2022 年 5 月 25 日
You can concatenate all the vectors and use function of max by the given dimension. For example
x=[1,3,6,9].';
y=[2,4,5,8].';
A=[x, y]
A = 4×2
1 2 3 4 6 5 9 8
m=max(A, [], 2)
m = 4×1
2 4 6 9

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by