calculate mean and max values using the groupsummary command
이전 댓글 표시
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
Chunru
2022년 9월 6일
You need to conver those char arrays into numbers first. Can you attach a small portion of the data?
Tiziano Bagnasco
2022년 9월 6일
Stephen23
2022년 9월 6일
@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
2022년 9월 6일
Tiziano Bagnasco
2022년 9월 7일
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)
답변 (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")
카테고리
도움말 센터 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!