hourly average for the monthly data

i want to hourly average the data given follow, for each day in month (4th column is the value which i want to hourly average) i try looping the following program still not getting result, please you can help me with this.
clc
clear
t=xlsread('jan',1,'A1:A'); % t=xlsread('worksheet name' ,1,'Range of elements')
date1 = datevec(t) % Convert char into vector form
elecf = xlsread('jan',1,'B1:B');
[a,~,c] = unique(date1(:,1:4),'rows');
for i=1:30
out(i,1)= [a,zeros(size(a,1),2),accumarray(c,elecf(:,1),[],@nanmean)];
out(i,2)= [a,zeros(size(a,1),2),accumarray(c,elecf(:,1),[],@nanmean)];
end

Answers (1)

Unless you're using a very outdated version of matlab, there's a much easier way to do everything you've done
t = readtable('jan', 'A:B'); %read excel (? it would be better to specify the file extension) file all at once
%Normally, if column A is a date in excel, t.Var1 would be datetime
%If not, convert it to datetime, not datenum
%t.Var1 = datetime(t.Var1, 'InputFormat', ... %format to specify)
t = table2timetable(t); %convert to timetable
retime(t, 'hourly', 'mean') %get hourly average

This question is closed.

Asked:

on 4 Feb 2019

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!