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
Click For Summary
SUMMARY

The discussion focuses on exporting images in a loop using Mathematica. The original code attempted to store graphics in a string variable, which resulted in an error. The solution provided involves directly exporting the rasterized images within the loop, eliminating the need for intermediate string storage. The corrected code successfully exports images named "image0.jpg", "image1.jpg", "image2.jpg", and "image3.jpg" to the specified directory.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of image processing concepts in Mathematica
  • Knowledge of the Rasterize function in Mathematica
  • Basic file handling and export techniques in Mathematica
NEXT STEPS
  • Explore advanced image processing techniques in Mathematica
  • Learn about the Export function in Mathematica for various file formats
  • Investigate the use of loops and control structures in Mathematica
  • Study the Rasterize function and its options for different output resolutions
USEFUL FOR

Mathematica users, graphic designers, and developers involved in image processing and automation tasks.

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
 
  • 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]
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 52 ·
2
Replies
52
Views
13K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 8 ·
Replies
8
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K