I have a code but now sure how it works please help

[C,I]=max(sum(a,2));
can some body explain how variables C and I change in 3x3 matrix. thanks in advance

 Accepted Answer

Etan - is a the 3x3 matrix that you are referring to? If it is, then
sum(a,2)
calculates the sum of each row, returning a 3x1 column vector. Then
[C,I]=max(sum(a,2));
will set C to the max element in that 3x1 vector, with I the index of that max element in the vector (so a value between 1 and 3, since there are three rows).

More Answers (0)

Community Treasure Hunt

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

Start Hunting!