How to plot average monthly data from excel using matlab R2013a?

1 次查看(过去 30 天)
Hello, I am trying to open data in excel file and then plot average monthly data. my code shown like this:
*filename ='Palembang.xlsx';
[num, txt, alldata]= xlsread(filename);
data = num(:,4);
jan = mean(data(7:361,:)); % raw data 7 until 361
feb = mean(data(362:844,:));
mar = mean(data(845:1201,:));
apr = mean(data(1202:1542,:));
may = mean(data(1543:1869,:));
jun = mean(data(1870:2261,:));
jul = mean(data(2262:2536,:));
aug = mean(data(2537:3051,:));
sep = mean(data(3052:3616,:));
oct = mean(data(3617:4297,:));
nov = mean(data(4298:4833,:));
dec = mean(data(4834:5273,:));
%get all the months of 2014
startdate = datenum('01-01-2014','dd-mm-yyyy');
enddate = datenum('31-12-2014','dd-mm-yyyy');
xdata = linspace(startdate,enddate,12);
ydata =
plot(xdata,ydata)
hold on
datetick('x','mmm','keepticks');
hold off*
in ydata it's still blank, because I dont know yet what command should I write there to plot the average data for each month? I hope somebody knows a better way to do it. thank you for everyone
  1 个评论
Kuifeng
Kuifeng 2016-4-17
%something like
MthMatrix = nan(31,12) %create the matrix
%Then find the location of 1st day of each month, and fill the columns respectively.
then I believe you can do the rest.

请先登录,再进行评论。

采纳的回答

Kuifeng
Kuifeng 2016-4-16
ydata = [jan feb mar apr may jun ...
jul aug sep oct nov dec]; %it should work.
%other options, make a matrix of 12 columns representing each month
%fill empty date with NaN. use the function ydata = mean(matrix, 2)
  1 个评论
nsyn
nsyn 2016-4-17
thank you Kuifeng, it's work.. I want to try other options, like you mention above. can you explain more about the matrix that you mean?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by