1
$\begingroup$

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}]]
$\endgroup$
1

2 Answers 2

0
$\begingroup$

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]
$\endgroup$
1
  • $\begingroup$ 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! $\endgroup$ Feb 20, 2015 at 18:00
2
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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! $\endgroup$ Feb 20, 2015 at 17:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.