How can I compress a table
6 次查看(过去 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!