find maximum number in a range of data

8 vues (au cours des 30 derniers jours)
C.G.
C.G. le 22 Oct 2021
Commenté : C.G. le 22 Oct 2021
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

Réponse acceptée

Jan
Jan le 22 Oct 2021
Modifié(e) : Jan le 22 Oct 2021
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 commentaire
C.G.
C.G. le 22 Oct 2021
Thank you so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by