I have a folders with this hierarchy :
Data meteo
Avril
Day1
file.xls
Day2
file.xls
Day3
file.xls
May
Day1
file.xls
Day2
file.xls
Day3
file.xls
June
Day1
file.xls
Day2
file.xls
Day3
file.xls
I need to read all files in those folders and choose just some columns to work with and write them in another directory with the same hierarchy.
I'm new on Matlab and I tried to test with this code.
D = 'data meteo';
DESTINATION = "data meteo destination"
S = dir(fullfile(D,'*'));
N = setdiff({S([S.isdir]).name},{'.','..'}); % number of subfolders of D.
for ii = 1:numel(N)
T = dir(fullfile(D,N{ii},'*'));
C = {T([T.isdir]).name}; %
for jj = 1:numel(C)
myExcelFile = fullfile(D,N{ii},C{jj});
%data = xlsread(myExcelFile);
data1=xlsread(myExcelFile,'A:A');
data2=xlsread(myExcelFile,'B:B');
data3=xlsread(myExcelFile,'C:C');
data4=xlsread(myExcelFile,'E:E');
data=[data1 data2 data3 data4]
%print(data)
xlswrite(DESTINATION,fullfile(D,N{ii},C{jj}));
end
end
I need to have result as the same hierarchy folders :
Data meteo Destination
Avril
Day1
file.xls
Day2
file.xls
Day3
file.xls
May
Day1
file.xls
Day2
file.xls
Day3
file.xls
June
Day1
file.xls
Day2
file.xls
Day3
file.xls
I've edited/expanded your code, and it seems to achieve what I think you're after when I try it on the fake directories I created for it, but see if it works for you (but I'd recommend testing it on a COPY of your data - in case something doesn't work and it changes/overwrites the original files).
The main changes I made were:
to add the setdiff function you used for N= also for C=, to ignore the '.' and '..' directories.
to change your code for myExcelFile to get the file itself rather than the 'Day1' directory
to add code that makes matching directories within your DESTINATION directory, to save the new files in.