MATLAB Answers


Need to manage the folders Hierarchy and extract the data for analysis

Asked by bushra raza on 27 Mar 2019
i have timeseries data of many years( 1971-2090) in many different folders with netcdf format. i want to extract the data from these NC files for specific past and future years separately.
Folders Hierarchy is like :
MainFolder has many subfolders like Run_1, Run_2,Run_3,and Run_4, and so on.
each subfolder Run(1,2,3,4) has two subfolders(hourly,daily), having all years data.
the filename is like "" ,
i have formulated the code for one specif Run folder, and got all years data in timetable.[ the code is attached ].
later i am successfully using the timetable data for specific years by using timerange option of timetable.
then i just change the run folder number and execute the script for next folder, one by one.
i am anxious to get an advice on my working. is there any short method to do all that?
also, as you can see the code, i am extracting all the long years data(though it takes processing time as well).
if i want to extract just few years record like 30 years only, instead of all years, how can i do that? please advise me.
function SimulatedData_Run475_Hourly = getSimulatedDataset(runNumber)
%creates simulated Dataset from the given runNumber
folderType = 'hourly' ;
%setting path
path_SimulatedData = 'D:\Project\SimulatedData\run_' ;
run_Number = runNumber;
path_SimulatedData =strcat(path_SimulatedData,num2str(run_Number),'\',folder_Type,'\');
strstart_Filename = 'timmendorf*' ;
% Get file list
allfile_Names = getFileList(path_SimulatedData,strstart_Filename);
timeArray =NaT;
zosArray = [] ;
allTimeArray = [];
allZosArray = [];
% Read data from the list of all nc files
for i = 1:length(allfile_Names)
[timeArray,zosArray] = getDataFromNCFile(allfile_Names{i});
allTimeArray= [allTimeArray; timeArray];
allZosArray = [allZosArray; zosArray];
end % end of i
SimulatedData_Run475_Hourly = timetable(allTimeArray,allZosArray);
end %end of function
function allfile_Names = getFileList(Path,strstart_Filename)
% Get list of all files from the given path and start string of the file
% name
givenPath = Path;
givenStr_File = strstart_Filename ;
fileList = dir(fullfile(givenPath, givenStr_File ));
allfile_Names = arrayfun(@(X) fullfile(givenPath,, fileList, 'uni', 0);


Sign in to comment.

0 Answers