フィルターのクリア

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 Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by