MATLAB: How to calculate formula using loop

convert

Hello!
Excel file format as follows:
  • A column: Year (from 1998 to 2018)
  • B column: Day of the year
  • C column: Hour
I'd like to convert the values of B and C column as year.
Doy= C/24+B
Formula is:
Time=A+(Doy/365) or Time=A+(Doy/366)
Dividing 365 or 366 is related to divide by 4. That's why I benefitted from modulo operation but I didn't do what I want.
data=xlsread('R.xlsx');
Doy=data(:,2)+(data(:,3)/24);
M = mod(data(:,1),4);
j=1;
for i=1:176784;
if M ==0
Time=data(:,1)+(Doy/366);
else M~=0
Time=data(:,1)+(Doy/365);
j=j+1;
end

Best Answer

data = xlsread('R.xlsx');
Doy = data(:,2)+(data(:,3)/24);
yearlen = 365 + (eomday(data(:,1),2) == 29); %trick
Time = data(:,1) + Doy ./ yearlen;