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);
  1 件のコメント
C.G.
C.G. 2021 年 10 月 22 日
Thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by