You can actually do this in Matlab without needing a for loop. If I'm interpreting your question correctly, you're asking to find which row in a matrix contains the maximum sum. To achieve this, use the max and sum commands.
totWatch = sum(Matrix2,2);
totBought = sum(Matrix3,2);
This gives us two vectors of 3x1 (cat, dog, hamster). Let's find which have a watch count above 50 AND a sell count above 30:
isPopular = (totWatch > 50) & (totBought > 30)
isPopular =
So strangely, hamsters are more popular than dogs. To find the most popular of each in an automated fashion you can use the max command, which can give you both the max value and the index of that value. For the most bought, for instance:
[maxB, ixB] = max(totBought)
maxB =
ixB =
Tells us that 42 pets of one type were sold, and this occurred in Row 3, the hamsters.
(edit: spelling)
Best Answer