find maximum number in a range of data

8 次查看(过去 30 天)
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