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
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
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!