how to create table Date/Value

1 visualización (últimos 30 días)
Luca Re
Luca Re el 7 de En. de 2024
Comentada: Star Strider el 7 de En. de 2024
i have this data (pic1) and i want similar pic2
Do I have to create the table by entering the values manually or is there a function to do this?
  1 comentario
Dyuman Joshi
Dyuman Joshi el 7 de En. de 2024
Unless you provide specific and necessary details, in written form, explaining what the expected output is, I will be closing the question.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 7 de En. de 2024
The unstack function works here.
Try this —
LD = load('matlab_data.mat')
LD = struct with fields:
prof: [728×1 double] dat: [728×1 datetime]
T1 = table(year(LD.dat),month(LD.dat,'shortname'),LD.prof)
T1 = 728×3 table
Var1 Var2 Var3 ____ _______ _______ 2022 {'Jan'} 0 2022 {'Jan'} 200.25 2022 {'Jan'} 346.25 2022 {'Jan'} -384.75 2022 {'Jan'} -171.5 2022 {'Jan'} 1026.2 2022 {'Jan'} 30.5 2022 {'Jan'} 0 2022 {'Jan'} -64.5 2022 {'Jan'} 39 2022 {'Jan'} 1695.8 2022 {'Jan'} 278.5 2022 {'Jan'} 12.5 2022 {'Jan'} 146.25 2022 {'Jan'} 0 2022 {'Jan'} -62.75
ResultSum = unstack(T1, 'Var3', 'Var2');
ResultSum.Properties.VariableNames{1} = 'Year'
Result = 2×13 table
Year Apr Aug Dec Feb Jan Jul Jun Mar May Nov Oct Sep ____ _______ _______ _______ _______ ______ ______ _______ _____ ______ _____ ______ _______ 2022 -2089.8 2563.8 -802.25 2864.8 1704.6 8589.7 -76.6 10816 8181.1 207.5 2008 614.85 2023 -5200.1 -657.25 1442.1 -355.12 5467.4 -227.2 -2292.4 6561 2739.1 3667 3315.6 -4046.3
The unstack function sums the data by default for each month. Other options are available by defining the appropriate function.
Example —
ResultMean = unstack(T1, 'Var3', 'Var2', 'AggregationFunction',@mean);
ResultMean.Properties.VariableNames{1} = 'Year'
Result = 2×13 table
Year Apr Aug Dec Feb Jan Jul Jun Mar May Nov Oct Sep ____ _______ _______ _______ _______ ______ ______ _______ ______ ______ ______ ______ _______ 2022 -69.658 82.703 -25.879 102.31 54.987 277.09 -2.5533 348.9 263.91 6.9167 64.774 20.495 2023 -173.34 -21.202 49.726 -12.683 176.37 -7.329 -76.412 211.65 88.357 122.23 106.95 -134.88
.
  6 comentarios
Luca Re
Luca Re el 7 de En. de 2024
👍👍
Star Strider
Star Strider el 7 de En. de 2024
Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Tables 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