0
$\begingroup$

I have two lists of files with slightly different naming conventions

files1 = {"DTideal_circ_def=000um_astX=000um_astY=410um.png","DTideal_circ_def=050um_defX=000um_defY=010um.png"}

files2={"DT120_blur7_Defoc=000um_AstigX=000um_AstigY=410um.png",
"DT120_blur7_Defoc=000um_AstigX=460um_AstigY=310um.png",
"DT120_blur7_Defoc=000um_AstigX=460um_AstigY=360um.png",
"DT120_blur7_Defoc=000um_AstigX=460um_AstigY=410um.png",
"DT120_blur7_Defoc=000um_AstigX=460um_AstigY=460um.png",
"DT120_blur7_Defoc=050um_AstigX=000um_AstigY=010um.png",
"DT120_blur7_Defoc=050um_AstigX=000um_AstigY=060um.png",
"DT120_blur7_Defoc=050um_AstigX=000um_AstigY=110um.png",
"DT120_blur7_Defoc=050um_AstigX=000um_AstigY=160um.png",
"DT120_blur7_Defoc=050um_AstigX=000um_AstigY=210um.png",
"DT120_blur7_Defoc=050um_AstigX=000um_AstigY=260um.png"}

I need to create pairs of files the paremeters of which are matching, i.e. to get

{{"DTideal_circ_def=000um_astX=000um_astY=410um.png","DT120_blur7_Defoc=000um_AstigX=000um_AstigY=410um.png"},
{"DTideal_circ_def=050um_defX=000um_defY=010um.png","DT120_blur7_Defoc=050um_AstigX=000um_AstigY=010um.png"}}
$\endgroup$

1 Answer 1

1
$\begingroup$

First, join the two groups:

Join[files1, files2]

Then gather them by their last 3 numbers like:

StringCases["DT120_blur7_Defoc=050um_AstigX=000um_AstigY=260um.png", DigitCharacter ..]

(*Out: {"120", "7", "050", "000", "260"} *)


StringCases["DT120_blur7_Defoc=050um_AstigX=000um_AstigY=260um.png", DigitCharacter ..][[-3;;]]

(*Out: {"050", "000", "260"} *)


GatherBy[Join[files1, files2], StringCases[#, DigitCharacter ..][[-3 ;;]] &]

Then select groups that have two elements:

Select[GatherBy[Join[files1, files2], StringCases[#, DigitCharacter ..][[-3 ;;]] &], Length[#] == 2 &]

(*Out: {{"DTideal_circ_def=000um_astX=000um_astY=410um.png", 
         "DT120_blur7_Defoc=000um_AstigX=000um_AstigY=410um.png"}, 
        {"DTideal_circ_def=050um_defX=000um_defY=010um.png", 
         "DT120_blur7_Defoc=050um_AstigX=000um_AstigY=010um.png"}} *)
$\endgroup$
1
  • $\begingroup$ That's perfect! Thank you so much! $\endgroup$
    – T. Rihacek
    Commented Feb 23, 2021 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.