calculate mean and max values using the groupsummary command
Mostra commenti meno recenti
Hello everyone,
As you can see from the attached picture I have successfully imported a large table matrix (T2) that shows certain wave motion variables for several years (hourly). I am trying to study the mean and maximum yearly values using "groupsummary" ( more or less like this: T22 = groupsummary(T2,"Var1","year",'mean'); ) but the command doesn't work and I am pretty sure it is because the 3rd and 6th columns have values between apostrophes ( 'x' ). I have run the same command in other situations and it works perfectly fine so I guess that the solution would be to get rid of those apostrophes..
Is there a smart way to do that? Of course I cannot do it manually since the matrix is extremely large.
Thank you in advance for your help and patience.

6 Commenti
Chunru
il 6 Set 2022
You need to conver those char arrays into numbers first. Can you attach a small portion of the data?
Tiziano Bagnasco
il 6 Set 2022
Stephen23
il 6 Set 2022
@Tiziano Bagnasco: the best solution would be to fix your data importing, so that the numeric data are imported as numeric and not as text. If you want us to help you with that, please upload a sample data file by clicking the paperclip button.
Tiziano Bagnasco
il 6 Set 2022
Tiziano Bagnasco
il 7 Set 2022
Seems your data can be retrieved by using readtable without any issues. Below shows the data from your attached csv file on year 2004.
On the other hand, since your data are already separated on a yearly basis. There is no need to use function groupsummary to determine the mean and maximum values for each year. You can just use function mean or max directly.
data = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1117965/Wave%20Data%202004_Open%20Data_WLC.csv','VariableNamingRule','preserve');
head(data,5)
Risposte (1)
tt = readtimetable("https://in.mathworks.com/matlabcentral/answers/uploaded_files/1117915/Wave%20Data%201994_Open%20Data_WLC.csv","VariableNamingRule","preserve")
retime(tt(:,vartype("numeric")),"yearly","mean")
retime(tt(:,vartype("numeric")),"yearly","max")
Categorie
Scopri di più su Tables in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!