Saving an image in a for loop with an updated name

  • Context: Mathematica 
  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    Image Loop
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
member 428835
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
 
Physics news on Phys.org
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
 
Reply
  • Like
Likes   Reactions: member 428835
Dale said:
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]