![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/344395/image.png)
How to make an histogram for month with datetime series, the data is windvelocity for a 1 year?
23 次查看(过去 30 天)
显示 更早的评论
Hi everybody, thank you so much for reading me, i really appreaciate, so i have a little problem, is very simple i think, i want to do an histogram for every months, i have my data in datetime, and i have the wind velocity, but i want to know the frequency of the data for months, but i don't know what i can't
this is my code right now:
clear;clc;
numData = xlsread('enerosolar.xlsx','EneDicV')
vel = numData(:,1);
Dia = numData(:,2);
tEnersol=readtable('enerosolar.xlsx','Sheet','EneDicV'); % read into a table object
tEnersol.Properties.VariableNames={'Vel','Dia'}; % assign variable names
yr=2014; % need the proper year
tEnersol.Date=datetime(yr,1,tEnersol.Dia); % and create a date column
tEnersol.Date.Format='dd/MM'; % display date format
hB=bar(tEnersol.Vel); % bar plot in descending order vs ordinal position
hAx=gca; % get axes handle...
xticks(1:7:365) % about all the ticks there's room for...
xticklabels(cellstr(tEnersol.Date(xticks))) % use the date string as tick labels
hAx.XTickLabelRotation=45; % rotate so can have chance to read...
xlabel('Dia del año'), ylabel('Velocidad de viento promedido diaria[m/s]');
perc = hline(2.85154314702398,'r', 'Velocidad de viento promedio '); hold on
perc = hline(2.85154314702398,'r', '2.85 m/s '); hold on
% perc = hline(4,'r', '4-3 m/s'); hold on
% perc = hline(3,'r', '3-1 m/s'); hold on
figure(2)
histogram(day(tEnersol.Vel))
xlabel('Velocidad de viento promedido diaria[m/s]'), ylabel('Cantidad de días del año TMYV');
ax2 = gca;
ax2.XTickLabelRotation = 45;
savefig('histogram.fig');
h = openfig('histogram.fig');
y = findobj(h, 'type', 'histogram')
figure(4)
Thank you so much for your valious time.
Best!!
Sophia
0 个评论
采纳的回答
Cris LaPierre
2020-8-11
I don't think you want to do histograms. Try a boxplot instead. Boxplots convey information about the spread of the data, but in a manner that makes it easy to compare the results from each month of the year.
boxplot(vel,month(tEnersol.Date),"Labels",month(tEnersol.Date,"shortname"))
This is the result based on the data you shared.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/344395/image.png)
4 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Weather and Atmospheric Science 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!