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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by