skipping files in for loop

4 Ansichten (letzte 30 Tage)
Macarena Santillan
Macarena Santillan am 22 Jul. 2021
Kommentiert: Jan am 22 Jul. 2021
Hello, I have multiple multiple files with similar names like 20210615_sh05_Ref.spe and 20210615_sh05_.spe.
I want to process only the files that contain the word Ref in it but my code is still processing all of them. I am assuming I am not indicating well the indices that I want to extract from strfind(w) but im not sure how to fix it.
Essentially, if the file contains the word reference, then process it, if not, then skip to the next file. Then I want to gather those results in an aray so I can average them.
Where did I go wrong? Thank you a lot!! (sorry for the language mix on my script I ran out of variable names)
tipodearchivo= dir('20210615_sh*.spe'); %Find all spe files in folder
nombres = {tipodearchivo.name};
cantidad = length(nombres);
cuenta = 0 ;
% Find reference files and take em out of the loop
w= strfind(nombres,'Ref');
for s=1:cantidad %Itiretae over shot files
nombres{s};
theresults=zeros(9,2);
Resultados=zeros([],5);
if ~isempty(w)%If h is not empty, then its a reference image, calculate
for t=1500:-1:600 %t=150:50:1600 %Time;
for g=150:100:1608
for u=g+100
[z,pos]=min (s1(g:u,t));
minpixel=g+pos;
[z1,pos1]=min (s1(u:u+100,t));
minpixel1= u+pos1;
Size= minpixel1-minpixel;
cuenta = cuenta+1 ;
Resultados(cuenta,:)=[cuenta t g u Size];
end
end
end
AverageSizeOneShot=mean(Resultados(:,5))% Size of one fringe Average of 101Pixels seems fine for shot 5
end
tamanios=mean(AverageSizeOneShot);
theresults(9,:)=[tamanios];
end
  1 Kommentar
Jan
Jan am 22 Jul. 2021
Some hints:
nombres{s}; % Omit this, because this does nothing
for g=150:100:1608
for u=g+100 % This is not a loop. Use this for clarity:
u = g + 100;
theresults(9,:) = tamanios; % No need for square brackets

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 22 Jul. 2021
Bearbeitet: Walter Roberson am 22 Jul. 2021
Change
if ~isempty(w)%If h is not empty, then its a reference image, calculate
to
if ~isempty(w{s})%If h is not empty, then its a reference image, calculate
However... you could instead
tipodearchivo= dir('20210615_sh*Ref.spe'); %Find all Ref spe files in folder
and then you would not need any filtering
Also, instead of the approach you are using with strfind() and isempty, you could instead use
w = contains(nombres,'Ref');
stuff
if w(i)

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by