How can I compress a table
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Christopher McCausland
il 28 Nov 2023
Modificato: Christopher McCausland
il 28 Nov 2023
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
Risposta accettata
Stephen23
il 28 Nov 2023
Modificato: Stephen23
il 29 Nov 2023
"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 Commenti
Più risposte (1)
Peter Perkins
il 28 Nov 2023
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.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!