3
$\begingroup$

I have Mathematica notebook that performs some operation say

a=2
b=3
c=5
d=4

how do I set the output file after evaluation to be named using the values $2,3,5,\ldots$

like "2_3_5_4_" such that the the naming automatically takes the values assigned to a,b,c d

$\endgroup$
  • $\begingroup$ Take a look at ToString, StringJoin etc. $\endgroup$ – Kuba May 13 '14 at 18:32
6
$\begingroup$

Your data

{a, b, c, d} = RandomInteger[9, 4];
data = a b c d;

Exporting with nice file-names featuring date and variable values using StringTemplate

Export[
 StringTemplate[
  "Date`1`_Values_a`2`_b`3`_c`4`.txt"
  ][DateString[{"Year", "Month", "Day"}], a, b, c]
 , data]
"Date20141201_Values_a7_b5_c3.txt"

Or using ToString and StringJoin as suggested by @Kuba

 Export[
  StringJoin["Data_", ToString /@ Riffle[{a, b, c, d}, "_"], ".txt"]
 , data]
"Data_7_5_3_7.txt"
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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