I am having trouble understanding Mathematica's scoping and what it does with loops. For example, if you would like to display a bunch of images, in python you may construct a loop and show the images in the loop. However, in Mathematica it doesn't seem that it works in the same way.

For example I am used to writing this type of script to achieve the idea above:

dothings[img_] := (

   f = GaussianFilter[img, 200];

For[i = 1, i < 3, i++,
 j = dothings[Import["C:\\Users\\Chase\\Pictures\\bg.jpg"]]

If the function is in a loop it does not return anything to the notebook output. DOes anyone know how to achieve this?

  • 1
    $\begingroup$ You don't need to Return[f], first of all. You can just define dothings as dothings[img_] := GaussianFilter[img, 200]. Second of all, For doesn't output anything, by default. If you want to just Print the images to the screen, then in the For loop, you will need to do Print[dothings[Import[ ... ]]]`. But it probably makes more sense to save them to a variable instead. $\endgroup$ – march Oct 17 '16 at 20:02
  • 4
    $\begingroup$ use Table or Map not For. your code mght be dothings[Import[#]]&/@ listoffilenames $\endgroup$ – george2079 Oct 17 '16 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.