match the same files in a loop

1 次查看(过去 30 天)
assia assia
assia assia 2021-7-6
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