match the same files in a loop

조회 수: 6 (최근 30일)
assia assia
assia assia 2021년 7월 6일
댓글: assia assia 2021년 7월 7일
Hello folks,
I have two folders with different parameters. I would like that my loop match and compute the files that has the same parameters. Any simple ideas on how can I do that please.
Example of the content of my folders:
The first folder:
StokesParameters_Synthetic_Star_Gain_10000000000-Real_5-Int_a=1.5_incl=90.0_pa=90.0_e=0.6_wave=900
The second folder:
Linear_Separable_Model_Synthetic_Star_Gain_10000000000-Real_5-a_Int_a=1.5_incl=90.0_pa=90.0_e=0.6_wave=900
  댓글 수: 2
Yongjian Feng
Yongjian Feng 2021년 7월 6일
It seems to me that you need to parse the file name string to extract parameters first. Then do the comparison.
assia assia
assia assia 2021년 7월 6일
What do mean by parse the file name string. Any concrete example please

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

답변 (1개)

dpb
dpb 2021년 7월 6일
f='StokesParameters_Synthetic_Star_Gain_10000000000-Real_5-Int_a=1.5_incl=90.0_pa=90.0_e=0.6_wave=900';
res=split(f,'_');
res=strcat(res(contains(res,"=")),';');
cellfun(@eval,res)
leaves in the workspace (in addition to anything else already there)
>> whos
a =
1.5000
incl =
90
pa =
90
e =
0.6000
wave =
900
>>
"Poofing" variables into the workspace isn't really an ideal thing to do; that was more just for grins to show could be done than in earnest "since you asked". :)
The problem here is that when you do another file/folder name string, it will overwrite those variables with the new copies of the same variables so you there's no way to actually compare the two.
What you really would need to do would be to set up an array and extract both sets into different arrays so can compare the two.
Or, you could do a string comparison of the entries in the res array from two cases by have two of those arrays--that would, presuming the naming patterns are consistent, let one find whether any of those strings were different.
  댓글 수: 1
assia assia
assia assia 2021년 7월 7일
thank you for your answer.
I have this code:
imgFolderStokes = fullfile('Data/Small_Data/Stokes/');
imgFolderLinear = fullfile('Data/Small_Data/Linear/');
imgStokes = imageDatastore(imgFolderStokes);
imgLinear = imageDatastore(imgFolderLinear);
numOfImgStokes = length(imgStokes.Files);
numOfImgLinear = length(imgLinear.Files);
for ii = 1:numOfImgStokes
% for jj = 1:numOfImgLinear
% imgStokes.Files{ii}
Stokes{ii} = fitsread(imgStokes.Files{ii})
Linear{ii} = fitsread(imgLinear.Files{ii})
tf = strcmp(Stokes{ii},Linear{ii})
end
But I had 0. There's no matching how can I improve this one to make it look just on the different parameters please.

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

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by