max value of N arrays

1 Ansicht (letzte 30 Tage)
simone zappalà
simone zappalà am 25 Mai 2022
Beantwortet: Voss am 25 Mai 2022
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]

Akzeptierte Antwort

Voss
Voss am 25 Mai 2022
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

Weitere Antworten (1)

MJFcoNaN
MJFcoNaN am 25 Mai 2022
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

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by