I am using max function. I need to be able to find 2 values.

My array contains 5 columns and 61 rows. I need to be able to find the max value of each column and the value in the 1st column associated with each maximum. The first column is years incrementing from 1950 to 2010. I seem to be able to get the correct max but can only get the index of the row where it occurs. Any ideas? I am a student and a newbie.

2 Comments

Illustration with 5 X 5 matrix with expected result?
1950 243 13 11 8
1951 137 10 8 5
1952 87 7 6 3
1953 104 14 6 4
1954 113 11 8 2
for instance, In column 2, if the max value is 243, I need to know how to output that number plus the year it occurs.
i.e. 1950 243

Sign in to comment.

 Accepted Answer

[m,idx]=max(yourMatrix(:,2:end));
newMatrix=[yourMatrix(idx,1),m'];

1 Comment

After playing with this a bit, I was able to get the result I needed. I need to review what I did wrong on my original code.
Thanks,

Sign in to comment.

More Answers (1)

READ THE HELP FOR MAX.
A = rand(61,5);
>> [MaxA,ind] = max(A)
MaxA =
0.97868 0.99908 0.96865 0.94517 0.9937
ind =
33 34 30 37 8
What information does the second return argument provide? How can you new use that variable to give you what you need?

3 Comments

I believe the second return argument provides the index to the row where the max occurs. I am needing to be able to output the value in the first column of my array where the max occurs in the second or third...columns.
David gave you code to do it, which is in fact coincidentally, exactly what I said to do.
Thank you...I couldn't see the forest for the trees.

Sign in to comment.

Categories

Products

Tags

Community Treasure Hunt

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

Start Hunting!