Plot average monthly flow from Jan-Dec for 'x' number of yrs on one plot using the provided data
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Harjas
le 29 Juil 2022
Réponse apportée : Cris LaPierre
le 29 Juil 2022
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 commentaires
Réponse acceptée
Cris LaPierre
le 29 Juil 2022
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!