Plot average monthly flow from Jan-Dec for 'x' number of yrs on one plot using the provided data
4 次查看(过去 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 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!