match the same files in a loop

1 view (last 30 days)
assia assia
assia assia on 6 Jul 2021
Commented: assia assia on 7 Jul 2021
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 Comments
Yongjian Feng
Yongjian Feng on 6 Jul 2021
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 on 6 Jul 2021
What do mean by parse the file name string. Any concrete example please

Sign in to comment.

Answers (1)

dpb
dpb on 6 Jul 2021
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 Comment
assia assia
assia assia on 7 Jul 2021
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.

Sign in to comment.

Categories

Find more on Variables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!