每日平均功能,可以从Excel数据中创建数据

时间:2014-05-09 16:06:19

标签: excel matlab function plot

我需要创建一个从excel数据中创建绘图数据的函数。 我的数据是每小时数据,我需要的图是每小时数据,每日平均每月平均数的图。我写了一些代码,但遗憾的是它无法正常工作

代码:

function makegraph

[a,b] = xlsread('C:\..matlabdata.xlsx'); %read data

lengte = size(b);

datumstring = b(2:end,:); 

formatin = 'mm/dd/yyyy' ; 

Datums= datenum(datumstring(:,1),formatin); 

[~,j] = size(a); 

timeplusphysicalflow = [datums, a(:,4)]; 

nrDates = size(datums,1);
subplot(3,1,1),  plot(datums,a(1:nrDates,4)); %plot voor de hourlyflow


datetick('x','mm/yy')

u = unique(datums); %bekijkt wat de unieke data zijn


[YU,MU,DU] = datevec(u); 
CurrentYear = YU(1); 
CurrentMonth = MU(1); 
CurrentDay = DU(1); 

nrMonth = unique(strcat(num2str(YU) ,num2str(MU)));  
nrDays = unique(strcat(num2str(YU) ,num2str(MU), num2str(DU)));

AverageMonths = zeros(length(nrMonth),1);

for k=1:length(nrMonth) 

index = (MU == CurrentMonth   & YU == CurrentYear);
AverageMonth(k) = mean(timeplusphysicalflow(index,2));  

AverageMonths(k) = [AverageMonth(k)];




end

AverageDays = zeros(length(nrDays),1);

for o=1:length(nrDays) 

index = (MU == CurrentMonth   & YU == CurrentYear & DU == CurrentDay);
AverageDay(o) = mean(timeplusphysicalflow(index,2));  

AverageDays(o) = [AverageDay(o)];


end


subplot(3,1,2),  plot(unique(strcat(num2str(YU),num2str(MU)),AverageMonths)); 
subplot(3,1,3),  plot(unique(strcat(num2str(YU),num2str(MU), num2str(DU)))); 

end

提前致谢

0 个答案:

没有答案