1

I'm trying to export a lot of files at one time with a For-loop. I'm using ToString so I can number the output files. It's not working. Does anyone know how to export many files with one looping construct?

Eq[κ_] := Round[1/2 + 1/2 Cos[(2 π)/κ  y t]]
κ1 = 128*5;
Mask3 = Table[Eq[κ1], {y, 30, 30 + 289}, {t, -100, 100}];
n = 200;
mine = Table[Partition[Table[Mask3[[i, j]], {i, 1, 17*17}], 17], {j, 1, n}];
movie = Table[Image[mine[[p]]], {p, 1, n}]

For[i = 1, i <= 3, i++,
  Export["OLEDmovie" <> ToString[i] <> ".bmp", movie[[i]], {i, 1, 3}]]
m_goldberg
  • 107,779
  • 16
  • 103
  • 257

2 Answers2

2

You have a ill-formed For-loop. Try

For[i = 1, i <= 3, i++, Export["OLEDmovie" <> ToString[i] <> ".bmp", movie[[i]]]]

or

Do[Export["OLEDmovie" <> ToString[i] <> ".bmp", movie[[i]]], {i, 1, 3}]

Both of these worked for me.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • Wow. I'm so sorry I didn't catch that. I was working with so many tables I just put that last part in automatically and the error messages didn't lead me think that was the issue. I'm sorry. Thank you for your help! – tablemountain Feb 20 '15 at 17:59
0

The well formed For loop can achieve your result as m_goldberg has illustrated. You can also use MapIndexed, e.g. say wished filename "OLEDmovie001.bmp",...

MapIndexed[Export["OLEDmovie"<>IntegerString[First@#2,10,3]<>".bmp",#1]&,movie]
ubpdqn
  • 60,617
  • 3
  • 59
  • 148
  • Thank you! I've never used MapIndex before but I don't recognize most of what's inside. I'll have to look into it. Thank you! – tablemountain Feb 20 '15 at 18:00