Lots of my time consists of analyzing huge sets of files recorded by and oscilloscope or some other device. Typically, I would try to use the same name for each file with a number at the end that increase each time. Then I can write a loop to load all of the files, then do analysis and create plots. This causes its own problems for several reasons such as: several loops must be used for different regions of the data (tek0000n for n = 1-9; tek000nn for nn = 10-99; tek00nnn for nnn = 100-999; etc) and broken loops when a single file in the data set is a different length or mission, and many other issues. Such a sustem looks like this where many conditional loops are used to fix the problem:
if m <10 & n < 10
for i = 1:n
Temp = dlmread([File,'/',File,'-0000',num2str(i),'.txt'],'\t',[17 0 3664 1]);
Frequency(:,i) = Temp(:,1);
Absorption(:,i) = Temp(:,2);
end
end
if m <10 & n < 100 & n > 10
for i = 1:9
Temp = dlmread([File,'/',File,'-0000',num2str(i),'.txt'],'\t',[17 0 3664 1]);
Frequency(:,i) = Temp(:,1);
Absorption(:,i) = Temp(:,2);
end
for i = 10:n
Temp = dlmread([File,'/',File,'-000',num2str(i),'.txt'],'\t',[17 0 3664 1]);
Frequency(:,i) = Temp(:,1);
Absorption(:,i) = Temp(:,2);
end
end
if m <10 & n < 1000 & n > 100
for i = 1:9
Temp = dlmread([File,'/',File,'-0000',num2str(i),'.txt'],'\t',[17 0 3664 1]);
Frequency(:,i) = Temp(:,1);
Absorption(:,i) = Temp(:,2);
end
for i = 10:99
Temp = dlmread([File,'/',File,'-000',num2str(i),'.txt'],'\t',[17 0 3664 1]);
Frequency(:,i) = Temp(:,1);
Absorption(:,i) = Temp(:,2);
end
for i = 100:n
Temp = dlmread([File,'/',File,'-00',num2str(i),'.txt'],'\t',[17 0 3664 1]);
Frequency(:,i) = Temp(:,1);
Absorption(:,i) = Temp(:,2);
end
end
if m > 10 & n < 1000 & n > 100
for i = m:99
Temp = dlmread([File,'/',File,'-000',num2str(i),'.txt'],'\t',[17 0 3664 1]);
Frequency(:,i) = Temp(:,1);
Absorption(:,i) = Temp(:,2);
end
for i = 100:n
Temp = dlmread([File,'/',File,'-00',num2str(i),'.txt'],'\t',[17 0 3664 1]);
Frequency(:,i) = Temp(:,1);
Absorption(:,i) = Temp(:,2);
end
end
if m < 10 & n > 1000
for i = 1:9
Temp = dlmread([File,'/',File,'-0000',num2str(i),'.txt'],'\t',[17 0 3664 1]);
Frequency(:,i) = Temp(:,1);
Absorption(:,i) = Temp(:,2);
end
for i = 10:99
Temp = dlmread([File,'/',File,'-000',num2str(i),'.txt'],'\t',[17 0 3664 1]);
Frequency(:,i) = Temp(:,1);
Absorption(:,i) = Temp(:,2);
end
for i = 100:999
Temp = dlmread([File,'/',File,'-00',num2str(i),'.txt'],'\t',[17 0 3664 1]);
Frequency(:,i) = Temp(:,1);
Absorption(:,i) = Temp(:,2);
end
end
Recently, google helped me discover a better method where you can actually tell matlab to read and record the files names in a specific folder. The, so long as all the data is the same length, a single loop can be used to import all of the data in a single folder. Here is an example:
The dir command reads the folder \Data, and a structure cell is created with the information for each file. Since I only care about the name, that cell can be extracted and trimmed. Then a single loop can be used to load all of the data into a useful format. To prevent errors if the files are not the same length, each data set is save in its own .mat file. These files can be quickly loaded in Matlab for later use.