How can I compress a table
조회 수: 5 (최근 30일)
이전 댓글 표시
I have an imported csv file. Containing a lot of rows How can I compress them so that al of the data of one year is stored in one row. (as in the picture below? I could not get the script from an much older matlab version running)
and what kind of type are the columns with the icon that looks like three sticky notes?
Kind regards Ellen
댓글 수: 2
Christopher McCausland
2023년 11월 28일
편집: Christopher McCausland
2023년 11월 28일
Hi Ellen,
The best way forward is probably to share a few rows of your data. Could you also explain a little more how you are expecing the output to look like? Sharing the old code may help here too.
In terms of the three sticky notes, I beleive they are known as 'pages', all that is being symbolised is that you have multiple data points stored in one structure field and row i.e. a 8784x1 double rather than a signal value as in the year feild. It makes a bit more sense here: Page-wise matrix multiplication - MATLAB pagemtimes - MathWorks Switzerland read the "More About" for a nice diagrame.
Hope this helps,
Christopher
채택된 답변
Stephen23
2023년 11월 28일
편집: Stephen23
2023년 11월 29일
"How can I compress them so that al of the data of one year is stored in one row. (as in the picture below?"
Your screenshot shows a non-scalar structure with fields 'year', 'month', etc.:
We can get such a structure by importing as a table and then a few simple manipulations on it:
T = readtable('KNMI310_1996-2023.csv')
U = varfun(@(v){v},T, 'GroupingVariables','YYYY')
S = table2struct(U) % take a look at S in the variable viewer.
댓글 수: 0
추가 답변 (1개)
Peter Perkins
2023년 11월 28일
Here's another possibility, using rowfun, that returns a table containing tables, which maybe is easier to use than what you asked for:
T = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1554527/KNMI310_1996-2023.csv")
U = rowfun(@(MM,dd,HH,DD,FF,P){table(MM,dd,HH,DD,FF,P)},T, GroupingVariables="YYYY",OutputVariableNames="Data")
U.Data{1}
U.Data{1}.DD(1:5) % etc.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!