This si the full code of Parallelanalysis function;
function[EnsambleVectorPar, Total] = Parallelanalysis(RadLat, RadLon, RadO3)
%% 6: Pre-process the data for parallel processing
% This takes the 3D array of data [model, lat, lon] and generates the
% data required to be processed at each location.
% ## This process is defined by the customer ##
% If you want to know the details, please ask, but this is not required
% for the module or assessment.
[Data2Process, LatLon] = PrepareData(Hourlydata, Lat, Lon);
%% Parallel Analysis
%% 7: Create the parallel pool and attache files for use
PoolSize = 4 ; % define the number of processors to use in parallel
if isempty(gcp('nocreate'))
parpool('local',PoolSize);
end
poolobj = gcp;
% attaching a file allows it to be available at each processor without
% passing the file each time. This speeds up the process. For more
% information, ask your tutor.
addAttachedFiles(poolobj,{'EnsembleValue'});
% %% 8: Parallel processing is difficult to monitor progress so we define a
% % special function to create a wait bar which is updated after each
% % process completes an analysis. The update function is defined at the
% % end of this script. Each time a parallel process competes it runs the
% % function to update the waitbar.
DataQ = parallel.pool.DataQueue; % Create a variable in the parallel pool
%
% % Create a waitbar and handle top it:
hWaitBar = waitbar(0, sprintf('Time period %i, Please wait ...', idxTime));
% % Define the function to call when new data is received in the data queue
% % 'DataQ'. See end of script for the function definition.
afterEach(DataQ, @nUpdateWaitbar);
N = Num2Process/Steps; % the total number of data to process
p = 1; % offset so the waitbar shows some colour quickly.
%% 9: The actual parallel processing!
% Ensemble value is a function defined by the customer to calculate the
% ensemble value at each location. Understanding this function is not
% required for the module or the assessment, but it is the reason for
% this being a 'big data' project due to the processing time (not the
% pure volume of raw data alone).
T4 = toc;
parfor idx = 1: Num2Process % size(Data2Process,1)
[EnsembleVectorPar(idx, idxTime)] = EnsembleValue(Data2Process(idx,:,:,:), LatLon, RadLat, RadLon, RadO3);
if idx/Steps == ceil(idx/Steps)
send(DataQ, idx/Steps);
end
end
close(hWaitBar); % close the wait bar
T3(idxTime) = toc - T4; % record the parallel processing time for this hour of data
fprintf('Parallel processing time for hour %i : %.1f s\n', idxTime, T3(idxTime))
end % end time loop
T2 = toc;
delete(gcp);
%% 10: Reshape ensemble values to Lat, lon, hour format
EnsembleVectorPar = reshape(EnsembleVectorPar, 696, 396, []);
fprintf('Total processing time for %i workers = %.2f s\n', PoolSize, sum(T3));
Total = sum(T3);
end