function [time,expdays] = timeconvert(doy,hhmm,sec); % [time,expdays] = timeconvert(doy,hhmm,sec); % % This function creates decimal time and expdays vectors from an array of data A % where time is recorded in day-of-year, hour-minute, and potentially seconds. % Example: A(1,1:3) = 1 1210 05 corresponds to 12:10:05 on January 1. % A(1,1:2) = 244 820 corresponds to 8:20 on August 31. % = 32 1530 corresponds to 3:30pm on February 1 % % Usage: having a time vector in decimal format allows you to easily plot % variables that are a function of time and which span several days. % % Inputs: % doy = day of year vector = A(:,doy_col), where A is the data array and doy_col is % the column number for the day of year data % hhmm = hour/minute vector = A(:,hhmm_col), where A is the data array and hhmm_col is % the column number for the hour/minute data of form HHMM (i.e. 1:15pm = 1315) % sec = seconds vector = A(:,sec_col). % % NOTE: size(hhmm) must equal size(doy) which much equal size(sec). % % Outputs: % time = row x 1 array containing the time of each row-record of A in % decimal format, i.e. 12:00:00 on day 210 would be recorded as 210.5 % expdays = (# of experiment days in A) x 1 array % each entry contains a different day of year % % If seconds are not recorded in A, then do this: % % [time,expdays] = timeconvert(A(:,doy_col),A(:,hhmm_col),zeros(size(A(:,doy_col)))) % % Written by Brian Hornbuckle, February 14, 2000. % Modified by Brian Hornbuckle on October 3, 2000, June 5, 2001, March 30, 2011. [rows] = length(hhmm); % time = hours*(day/24 hours) + minutes*(day/(24*60minutes)) + seconds*(day/(24*60*60seconds)) h = floor(hhmm./100); % hours m = (hhmm./100 - h).*100; % minutes time = doy + h./24 + m./(24*60) + sec./(24*60*60); %-------------- creating vector which contains experiment days currentday = 0; % initialize variables n = 0; for k = 1:rows day = doy(k); if day ~= currentday n = n+1; expdays(n) = day; currentday = day; end; end; expdays = expdays'; % change to row vector