필터 지우기
필터 지우기

skipping files in for loop

조회 수: 7 (최근 30일)
Macarena Santillan
Macarena Santillan 2021년 7월 22일
댓글: Jan 2021년 7월 22일
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
Jan
Jan 2021년 7월 22일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2021년 7월 22일
편집: Walter Roberson 2021년 7월 22일
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)
  댓글 수: 1
Macarena Santillan
Macarena Santillan 2021년 7월 22일
Thnak you SO much ! it works!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by