find maximum number in a range of data

조회 수: 8 (최근 30일)
C.G.
C.G. 2021년 10월 22일
댓글: C.G. 2021년 10월 22일
I have a matrix T, and I have asked it to find all the rows where the value in column 5 is between 2 numbers and save these as S1.
I now want it to tell me out of rows identified, what is the highest number that appears in column 6, and tell me this number and the corresponding number in column 5.
I tried the code below but it does not work, and it gives me a x1 of 0.1310 which isnt in the range of S1. Can anybody help?
file = dir('ATF_0.csv');
T = table2array(readtable(file.name));
T = T(T(:,6)<=-0.07,:);
S1 = T(:,5)>= 0.14 & T(:,5) <= 0.149; %find the rows where x coord is between the limits and save to S1
[y1, idx1] = max(T(S1,6)); %find the y coordinate which is maximum out of this group
x1 = T(idx1,5); %record the x coordinate that the y coordinate occurs at

채택된 답변

Jan
Jan 2021년 10월 22일
편집: Jan 2021년 10월 22일
In max(T(S1,6)) you are searching in the submatrix T(S1, :). But you use the result as index in the full matrix T. You want to apply theindex idx1 to T(S1, :).
S1 = T(:,5) >= 0.14 & T(:,5) <= 0.149;
TS1 = T(S1, :);
[y1, idx1] = max(TS1(:, 6));
x1 = TS1(idx1, 5);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by