Find Max values in each row
13 views (last 30 days)
Show older comments
Hi everyone, I have a Matlab question and I'm having some issues...
I have data (please see the data above) known as A1. I have 3 rows but row one is just the x-axis. I want to extract the max value in each row (rows 2 and 3) as well as the associated x-axis (row 1) value for each max value. The code I'm using is below:
[maxA1, index] = max(A1,[],2);
In this case, maxA1 rightfully gives me 1.6 and 2.3 as the max values for rows 2 an 3 respectfully. The index value is giving me just the column numbers (i.e., 4 or D in the case of excel and 3 or C in the case of excel). In reality, I am not interested in the column #s, I was hoping to get the corresponding x-axis values in row 1 instead (in this case, 500 and 400). I wouldn't mind to get the index/column #s as well but what I really need is the x-axis values.
Please is there a way or any suggestion on how the code can be modifie to give me the max values in rows 2 and 3 as well as their corresponding x-axis values (which is in row 1) and possibly the index/column number as well?
Thank you!
0 Comments
Accepted Answer
Voss
on 18 Jul 2022
A1 = [ ...
200 300 400 500 600; ...
1.2 1.3 1.4 1.6 1.2; ...
1.5 1.9 2.3 1.5 1.2];
Use the index you get to index into the first row of A1:
[maxA1, index] = max(A1,[],2)
maxX = A1(1,index)
(Same as above, except using only rows 2 through the end of A1:)
[maxA1, index] = max(A1(2:end,:),[],2)
maxX = A1(1,index)
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!