1
$\begingroup$

In the first line of my code the values of m and n are decided. After running it, three important lists are generated, say list1, list2 and list3. I am using

Save["list1-mn.m", list1]
Save["list2-mn.m", list2]
Save["list3-mn.m", list3]

at the final to save the results. But I have to change the name of these files every time I ran the code for different values of m and n, to avoid subscribing. Is there a way to auto change the name of the files according to the values of m and n? For example, if I put m=3 and n=5 at the beginning of the code, I have to change the scope of Save manually to

Save["list1-35.m", list1]
Save["list2-35.m", list2]
Save["list3-35.m", list3]

before running the code. Is there a way to do this automatically? For me, it is important to save the files, no matter if the function used is Save or another one.

$\endgroup$
2
$\begingroup$

I have to change the scope of Save manually to

Save["list1-35.m", list1] Save["list2-35.m", list2] Save["list3-35.m", list3]

You could try this and see if it works for you. Not tested.

n=2;
m=3;
(*list1,list2,list3 ready here*)
Do[
  fileName="list"<>ToString[k]<>"-"<>ToString[n]<>ToString[m]<>".m";
  Save[fileName,ToExpression["list"<>ToString[k]]]
  ,
  {k,1,3}
]
$\endgroup$
  • $\begingroup$ Can we do this with StringFormat? $\endgroup$ – ablmf Feb 4 at 17:40

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.