Clear Filters
Clear Filters

How to remove certain files from for loop data analysis?

2 views (last 30 days)
So for my research lab, I have been asked to make a polt of a data run, but to exclude 4 files which we have found to be corrupted.
The data is currently read in as a for loop set up, running from N1= first file to N2=lst file. and I am not sure how to amend it. I have tried just removing the files from the folder with the rest of the data files, but the code would run then. I also tried adding a section to the for loop which would say if the files are these number then set to 0, but it didn;t have an effect on my energy spectra. any ideas?
Here is the original code:
%%Startup
Name = input('Main File Name (exclude end numbers and extension): ', 's');
%Example: (Folder_Name)/(File_Name) ---> 011216/Run15_011216
N1 = input('Starting File Number: ');
N2 = input('Ending File Number: ');
hpf = input('Hours per File: ');
RunName = Name(8:length(Name));
SpectrumMaxCounts = 50; % By-hand setting of energy spectrum maximum scale
tic
Files = zeros(2048,N2-N1+1);
Counts = zeros(N2-N1+1,5);
ZeroErr = zeros(N2-N1+1,5);% kludge to kill error bars in plots
Po210lo = 575;
Po210hi = 636;
Po218lo = 637;
Po218hi = 664;
Po216lo = 665;
Po216hi = 734;
Po214lo = 735;
Po214hi = 830;
Po212lo = 831;
Po212hi = 1050;
%%Import
for n = N1:N2
if N1 == 0
File = sprintf('%s%.3d.mca',Name, n);
Data = importdata(File,'\t',2061);
Files(:,n+1) = str2num(char(Data(13:2060)));
Counts(n-N1+1,1) = sum(Files(Po210lo:Po210hi,n+1));
Counts(n-N1+1,2) = sum(Files(Po218lo:Po218hi,n+1));
Counts(n-N1+1,3) = sum(Files(Po216lo:Po216hi,n+1));
Counts(n-N1+1,4) = sum(Files(Po214lo:Po214hi,n+1));
Counts(n-N1+1,5) = sum(Files(Po212lo:Po212hi,n+1));
else
File = sprintf('%s%.3d.mca',Name, n);
Data = importdata(File,'\t',2061);
Files(:,n-N1+1) = str2num(char(Data(13:2060)));
Counts(n-N1+1,1) = sum(Files(Po210lo:Po210hi,n-N1+1));
Counts(n-N1+1,2) = sum(Files(Po218lo:Po218hi,n-N1+1));
Counts(n-N1+1,3) = sum(Files(Po216lo:Po216hi,n-N1+1));
Counts(n-N1+1,4) = sum(Files(Po214lo:Po214hi,n-N1+1));
Counts(n-N1+1,5) = sum(Files(Po212lo:Po212hi,n-N1+1));
end
if n == N1
LiveTime = hpf;
end
end
Time = (LiveTime*(N1-N1+1):LiveTime:LiveTime*(N2-N1+1))/24';
Here is how I tried to change it :
%%Startup
Name = input('Main File Name (exclude end numbers and extension): ', 's');
%Example: (Folder_Name)/(File_Name) ---> 011216/Run15_011216
N1 = input('Starting File Number: ');
N2 = input('Ending File Number: ');
N3= input('input files to exclude: ');
N4= input('input files to exclude: ');
N5= input('input files to exclude: ');
N6= input('input files to exclude: ');
hpf = input('Hours per File: ');
RunName = Name(8:length(Name));
SpectrumMaxCounts = 50; % By-hand setting of energy spectrum maximum scale
tic
Files = zeros(2048,N2-N1+1);
Counts = zeros(N2-N1+1,5);
ZeroErr = zeros(N2-N1+1,5);% kludge to kill error bars in plots
Po210lo = 575;
Po210hi = 636;
Po218lo = 637;
Po218hi = 664;
Po216lo = 665;
Po216hi = 734;
Po214lo = 735;
Po214hi = 830;
Po212lo = 831;
Po212hi = 1050;
%%Import
for n = N1:N2
if N1 == 0
File = sprintf('%s%.3d.mca',Name, n);
Data = importdata(File,'\t',2061);
Files(:,n+1) = str2num(char(Data(13:2060)));
Counts(n-N1+1,1) = sum(Files(Po210lo:Po210hi,n+1));
Counts(n-N1+1,2) = sum(Files(Po218lo:Po218hi,n+1));
Counts(n-N1+1,3) = sum(Files(Po216lo:Po216hi,n+1));
Counts(n-N1+1,4) = sum(Files(Po214lo:Po214hi,n+1));
Counts(n-N1+1,5) = sum(Files(Po212lo:Po212hi,n+1));
else if n==N4:N6
File = sprintf('%s%.3d.mca',Name, n);
Data = importdata(File,'\t',2061);
Files(:,n-N1+1) =0
Counts(n-N1+1,1) = 0
Counts(n-N1+1,2) = 0
Counts(n-N1+1,3) = 0
Counts(n-N1+1,4) = 0
Counts(n-N1+1,5) = 0
else
File = sprintf('%s%.3d.mca',Name, n);
Data = importdata(File,'\t',2061);
Files(:,n-N1+1) = str2num(char(Data(13:2060)));
Counts(n-N1+1,1) = sum(Files(Po210lo:Po210hi,n-N1+1));
Counts(n-N1+1,2) = sum(Files(Po218lo:Po218hi,n-N1+1));
Counts(n-N1+1,3) = sum(Files(Po216lo:Po216hi,n-N1+1));
Counts(n-N1+1,4) = sum(Files(Po214lo:Po214hi,n-N1+1));
Counts(n-N1+1,5) = sum(Files(Po212lo:Po212hi,n-N1+1));
end
end
if n == N1
LiveTime = hpf;
end
end
Time = (LiveTime*(N1-N1+1):LiveTime:LiveTime*(N2-N1+1))/24';

Answers (1)

Nate
Nate on 25 Oct 2017
Hi Stephanie,
It sounds like you need to modify the script so that those files are ignored. By setting their data to 0, you are still likely affecting your results, since those 0's would (I assume here) have an effect on statistics such as mean or minimum.
It sounds like your changes did not have an effect on the data you were analyzing. Were you expecting them to show change?
If you could clarify your issue more specifically, I would be happy to help further.
Thanks,
Nate

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!