find maximum number in a range of data

8 visualizaciones (últimos 30 días)
C.G.
C.G. el 22 de Oct. de 2021
Comentada: C.G. el 22 de Oct. de 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

Respuesta aceptada

Jan
Jan el 22 de Oct. de 2021
Editada: Jan el 22 de Oct. de 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);

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by