MATLAB: Opening folders and read its information

folders

I'm new to the field of creating or opening folders from a script. I have tried many things and I always get "the file was not found".
This is my main director (C:\Deterministic\New Objectives) where 8 sub-folders are located and their names are:
Normal_4000_M
Normal_4000_M_2S
Normal_4000_M_S
Normal_4000_M+2S
Normal_4000_M+S
Normal_4000_P10
Normal_4000_P50
Normal_4000_p90
I want to access each folder and load its 'NPV_v_0.15.mat' and save it in a vector which is called RESULT.
Anyone can help please and thanks in advanced.

Best Answer

This should get you started:
D = 'C:\Deterministic\New Objectives';
S = dir(fullfile(D,'Normal_4000*'));
N = {S([S.isdir]).name};
C = cell(1,numel(N));
for k = 1:numel(N)
C{k} = load(fullfile(D,N{k},'NPV_v_0.15.mat'));
end
Your data will be in the cell array C. The folder names are listed in cell array N. If every .mat contains the same variables then you could easily concatenate them into one non-scalar structure:
T = [C{:}];
Read more: