% Loas data from separated folders and save in a structure array
% Chia-Feng Lu 2014.10.15
clear, close all
%% the variable names for each subject's data
VarName={'name','age','gender','height','weight','predata','postdata'};

%% recursivly load the data from folders and save in a structure array
dirname=[pwd filesep 'data'];
dirinfo=dir(dirname);
dirinfo(1:2)=[];  % remove . and ..
for i=1:length(dirinfo)
    load([dirname filesep dirinfo(i).name filesep dirinfo(i).name '.mat'])
    
    for j=1:length(VarName)
        eval(['NC(i).' VarName{j} '=' VarName{j} ';']);
    end
end

%% save the structure array as a *.mat matlab file
save('NC.mat','NC')