max value of N arrays

4 vues (au cours des 30 derniers jours)
simone zappalà
simone zappalà le 25 Mai 2022
Réponse apportée : Voss le 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]

Réponse acceptée

Voss
Voss le 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

Plus de réponses (1)

MJFcoNaN
MJFcoNaN le 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

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by