I have a data set consisting of 8 years from 2006-2013 of SST taken every 3 hours. There are some gaps in the data. I have already created a matrix 74*115*27192 (74 is the lon, 115 is the lat, and 27192 is the SST for all years. Now I have to calculate the daily mean. The Daily mean (Daily_mean) should generate a matrix of 74*115*X (X being the number of day). Instead it is generating a 74*115 matrix only. Any help. Thanks
clear all; close all;fileList = dir('C:\Users\User\Desktop\Master Thesis\data\yearly\Rosario');iniTime = datenum(1990, 1, 1, 0, 0, 0); cnt = 1;fullSST = zeros (74,115,21792);fullTime = zeros (2179,1);for f = 1:numel(fileList); filename = fileList(f).name; [dirname name ext] = fileparts(filename); if (strcmp(ext, '.nc')) disp(['Processing file: ', filename]); info = ncinfo (filename); dataLon = ncread (filename, 'longitude'); %loading longitude data
dataLat = ncread (filename, 'latitude'); %loading latitude data
dataSST = ncread (filename, 'potemp'); %loading SST
dataTime = ncread(filename, 'time'); dataSST=squeeze(dataSST); for t = 1:1:size(dataSST, 3) SST = dataSST(:, :, t); Time = double(dataTime(t)); currDate = addtodate(iniTime, Time, 'hour'); fullSST (:,:,cnt) = SST; fullTime (cnt) = currDate; cnt = cnt +1; end end end%Full data set
startDate = datenum([2007 1 1 0 0 0]);EndDate = datenum ([2013 12 31 0 0 0]);currDate = startDate;while (currDate <= EndDate) currDateVect = datevec(currDate); aDate = datenum([currDateVect(1) currDateVect(2) currDateVect(3) 0 0 0]); bDate = datenum([currDateVect(1) currDateVect(2) currDateVect(3) 23 59 59]); % find corresponding indices
start_index = find(fullTime >= aDate);%find data > than the StartTime
end_index = find(fullTime <= bDate); %find index of data ending in EndTime
index = intersect(start_index, end_index); if (numel(index) > 0) Daily_mean = mean(fullSST(:, :, index), 3); Daily_time = currDate; end currDate = addtodate(currDate, 1, 'day'); end
Best Answer