Plot average monthly flow from Jan-Dec for 'x' number of yrs on one plot using the provided data
5 ビュー (過去 30 日間)
古いコメントを表示
Hello MATLAB Community,
I want to plot the average monthly values from Jan-Dec for 'x' number of years on the same plot. I was able to calculate the average using groupsummary. How can I use the isbetween or any other function to separate out those years in varaible 'yr' from the Mean table and plot them in single plot. I have also attached the sample output which I am expecting to get.
clc
clear
close all
data = readtable('Test.xlsx');
Mean = groupsummary(data,'Date','month','mean');
yr=[1977,1988,1989,1991,2003]
0 件のコメント
採用された回答
Cris LaPierre
2022 年 7 月 29 日
Group by year and monthofyear. Then you can use ismember and reshape to identify and organize the data in a manner that will allow you to generate the desired plot.
file = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1082210/TEST%20(1).xlsx';
data = readtable(file);
Mean = groupsummary(data,{'Date_Time','Date_Time'},{'year','monthofyear'},'mean','WaterLevel')
yrs = [1977,1988,1989,1991,2003];
yr=ismember(str2double(string(Mean.year_Date_Time)),yrs);
x = reshape(Mean.monthofyear_Date_Time(yr),12,[]);
y = reshape(Mean.mean_WaterLevel(yr),12,[]);
plot(x,y)
xticklabels({'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'})
legend(string(yrs))
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!