Find Max values in each row

15 次查看(过去 30 天)
Learning
Learning 2022-7-18
评论: Voss 2022-7-19
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!

采纳的回答

Voss
Voss 2022-7-18
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)
maxA1 = 3×1
600.0000 1.6000 2.3000
index = 3×1
5 4 3
maxX = A1(1,index)
maxX = 1×3
600 500 400
(Same as above, except using only rows 2 through the end of A1:)
[maxA1, index] = max(A1(2:end,:),[],2)
maxA1 = 2×1
1.6000 2.3000
index = 2×1
4 3
maxX = A1(1,index)
maxX = 1×2
500 400

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by