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

2 views (last 30 days)
nsyn on 16 Apr 2016
Commented: Kuifeng on 17 Apr 2016
Hello, I am trying to open data in excel file and then plot average monthly data. my code shown like this:
*filename ='Palembang.xlsx';
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
Kuifeng on 17 Apr 2016
%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 on 16 Apr 2016
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)
nsyn on 17 Apr 2016
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?