Max/Min Values in a table

28 visualizaciones (últimos 30 días)
Eduardo Calderon
Eduardo Calderon el 18 de Feb. de 2018
Respondida: Steven Lord el 15 de Abr. de 2025
I'm trying to find the max and min values of a table, and the times that each max and min occurred, what function/syntax would I use to find these values? table =
24×4 table
t wsp1 wsp2 wsp3
__ ____ ____ ____
1 7.8 6.9 6.7
2 7.5 6.8 6.4
3 8.5 8.1 8
4 8.4 6.8 6.5
5 11.1 7.2 6.9
6 14.5 11.7 11.5
7 22.6 16 15.6
8 34.9 22.6 20
9 30 20.5 18.5
10 29.5 18.1 18
11 21.3 15.6 14.5
12 20.5 13.9 13.4
13 18.4 13.8 13
14 15.6 9.3 8.9
15 14 9.2 8.5
16 13.9 9.1 8.8
17 13 8 7.4
18 11.8 7 6.3
19 12.4 7.1 6.8
20 13.4 5.8 5.4
21 5.6 5.7 4.7
22 6.7 4.2 3.6
23 6.4 4.5 3.2
24 5.9 4.4 3.8

Respuestas (2)

Walter Roberson
Walter Roberson el 18 de Feb. de 2018
[min_vals, min_idx] = min(YourTable{:,2:4});
min_times = YourTable.t(min_idx);
Now min_vals(1) is the minimum wsp1 and that occurred at time min_times(1)

Steven Lord
Steven Lord el 15 de Abr. de 2025
As of release R2023a, you can directly call min on a table or timetable array as long as all the variables are of a data type that supports the calculation.
T = array2table(magic(5))
T = 5x5 table
Var1 Var2 Var3 Var4 Var5 ____ ____ ____ ____ ____ 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
[minValues, minLocations] = min(T)
minValues = 1x5 table
Var1 Var2 Var3 Var4 Var5 ____ ____ ____ ____ ____ 4 5 1 2 3
minLocations = 1x5 table
Var1 Var2 Var3 Var4 Var5 ____ ____ ____ ____ ____ 3 2 1 5 4
resultInVariableVar2 = T{minLocations.Var2, "Var2"}
resultInVariableVar2 = 5
See this documentation page for more information.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by