how to create table Date/Value

조회 수: 1 (최근 30일)
Luca Re
Luca Re 2024년 1월 7일
댓글: Star Strider 2024년 1월 7일
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
Dyuman Joshi
Dyuman Joshi 2024년 1월 7일
Unless you provide specific and necessary details, in written form, explaining what the expected output is, I will be closing the question.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2024년 1월 7일
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
Luca Re
Luca Re 2024년 1월 7일
👍👍
Star Strider
Star Strider 2024년 1월 7일
Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by