Saving an image in a for loop with an updated name

  • Mathematica
  • Thread starter joshmccraney
  • Start date
  • #1
2,029
114
Hello all!

I am trying to export image0, image1, image2, etc in a for loop. What I have is
Code:
For[i = 0, i < 4, i++,
 "image" <> ToString[i] =
  Rasterize[plfunc3dANGside2[6, 2, 115, 0.1*i], Background -> None,
   ImageResolution -> 1000];
 Export["/home/josh/ISS_drops/vibrations/" <> "image" <> ToString[i] <>
    ".jpg", "image" <> ToString[i]]
 ]
I get an error when I try running this. Any idea of a better way? My logic:
line 1: for loop specs
line 2: string name of image
line3-4: definition of the image
line5-6: export image
 

Answers and Replies

  • #2
Dale
Mentor
Insights Author
2021 Award
32,410
9,395
Line 2 evaluates to a String but line 3 evaluates to a Graphics. You cannot store a Graphics in a String. You probably want to use ToSymbol[ ] on your string
 
  • Like
Likes joshmccraney
  • #3
2,029
114
Line 2 evaluates to a String but line 3 evaluates to a Graphics. You cannot store a Graphics in a String. You probably want to use ToSymbol[ ] on your string
Amazing, and thanks! For anyone in the future, I have now changed the script to this

Code:
For[i = 0, i < 4, i++,
 Export["/home/josh/ISS_drops/vibrations/" <> "image" <> ToString[i] <>
    ".jpg", 
  Rasterize[plfunc3dANGside2[6, 2, 115, 0.1*i], Background -> None, 
   ImageResolution -> 1000]]
 ]
[\code]
 

Related Threads on Saving an image in a for loop with an updated name

  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
4
Views
244
Replies
5
Views
1K
Replies
3
Views
8K
Replies
3
Views
2K
Replies
1
Views
5K
Replies
4
Views
1K
Replies
3
Views
6K
Replies
1
Views
4K
Top