Febri Dwi Laksono
Febri Dwi Laksono

Reputation: 309

How do I sum the max value of every row in a matrix?

A=[ 2 4 8 20 0 0;
    1 3 6 18 22 0;
    0 3 5 8 18 20]

and then from the above matrix, I want to account average of max value of every rows. so I wish the result :

result=average(20+22+20)=20,67

thankf for your help.

Upvotes: 0

Views: 704

Answers (1)

estebane97
estebane97

Reputation: 1138

[C,I] = max(...) finds the indices of the maximum values of A, and returns them in output vector I. If there are several identical maximum values, the index of the first one found is returned.

for your problem

maxValues= max(A,[],2)
result=Mean(maxValues)

Upvotes: 1

Related Questions