How to vectorize max / min number in row

2 次查看(过去 30 天)
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 ...

采纳的回答

Stephen23
Stephen23 2020-2-14
>> 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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by