Find Max values in each row

조회 수: 12 (최근 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
  댓글 수: 2
Learning
Learning 2022년 7월 19일
Thank you!!
Voss
Voss 2022년 7월 19일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (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