How to vectorize max / min number in row

2 visualizzazioni (ultimi 30 giorni)
Ole
Ole il 14 Feb 2020
Commentato: Ole il 14 Feb 2020
Ho to vectorize the min and max value on each row for a matrix
a = linspace(2,5,10); b = linspace(0,8,10);
A = [a' b']
2.000000000000000 0
2.333333333333333 0.888888888888889
2.666666666666667 1.777777777777778
3.000000000000000 2.666666666666667
3.333333333333333 3.555555555555555
3.666666666666667 4.444444444444445
4.000000000000000 5.333333333333333
4.333333333333334 6.222222222222222
4.666666666666666 7.111111111111111
5.000000000000000 8.000000000000000
the result should be
maxr = 2, 2.33, 2.66,3 , 3.55 ...
minr = 0, 0.88, 1.77. 2.66, 3.33 ...

Risposta accettata

Stephen23
Stephen23 il 14 Feb 2020
>> max(A,[],2)
ans =
2.0000
2.3333
2.6667
3.0000
3.5556
4.4444
5.3333
6.2222
7.1111
8.0000
>> min(A,[],2)
ans =
0.00000
0.88889
1.77778
2.66667
3.33333
3.66667
4.00000
4.33333
4.66667
5.00000

Più risposte (0)

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by