Mathematica Exporting .png files with the same number of digits

  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    files
Click For Summary
The discussion centers on exporting plots as .png files in Mathematica, specifically addressing the issue of file naming conventions. The user seeks to format the output filenames to include leading zeros, resulting in titles like test01.png, test02.png, etc., instead of test1.png, test2.png, and so on. Suggestions include checking the Mathematica documentation and using an If statement to conditionally add a leading zero based on the file number. The user expresses gratitude for the input and confirms their understanding of the proposed solution.
member 428835
Hi PF!

I'm trying to export plots of .png files as follows:
Code:
plot[t_] := 
 Plot[0.1 Exp[-2 \[Pi] t] Cos[\[Pi]*j*x], {x, -1, 1}, 
  PlotRange -> {{-1, 1}, {-1, 1}}, Axes -> False, Background -> Black,
   PlotStyle -> Thickness[0.02]]
dt = 0.1;
Do[Export["test" <> ToString[t/dt] <> "png", plot[t], 
  ImageResolution -> 300], {t, 0, 1, dt}]

But the issue is my output images are titled test1.png, test2.png,...,test13.png...etc. How do I change the file title to read test01.png, test02.png,...,test13.png?

I really appreciate it!
 
Physics news on Phys.org
joshmccraney said:
But the issue is my output images are titled test1.png, test2.png,...,test13.png...etc. How do I change the file title to read test01.png, test02.png,...,test13.png?
I had a quick look at the Mathematica documentation and at StackExchange, and there doesn't appear to be any simple way to apply a format to the numbers. I would suggest using an If testing whether to insert a leading 0.
 
  • Like
Likes member 428835
DrClaude said:
I had a quick look at the Mathematica documentation and at StackExchange, and there doesn't appear to be any simple way to apply a format to the numbers. I would suggest using an If testing whether to insert a leading 0.
Okay, I wasn't sure if I missed something. Thanks!
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 0 ·
Replies
0
Views
634
  • · Replies 52 ·
2
Replies
52
Views
13K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
5K