I have created a notebook with one fix variable that I want to run from 1 to 100. Every time the whole notebook (all cells) shall be executed for the given number. At the end of the notebook, it shall start from the beginning, changed variable and do it all over again. So it should work like a loop but I don't know how to do that in Mathematica.It would be great if someone knew an easy way to solve my problem.

I shorted the program a little but the key problem is hopefully clear.

The number I start with.

number = 1;

Than I load a single tiff image and detect an object.

original = Import["C:\\...\\2017-05-\
22_M963.tif", {"ImageList", number}];
edge = MorphologicalPerimeter[
  PeronaMalikFilter[original , 20, 0.02, 2] , 0.03]
data = PixelValuePositions[ImageCrop[edge, {1278, 1022}], White];

After a fit a want to save the data.

Export["2017-05-22_M963_W" <> ToString[number] <> 
  ".txt", {a, b, theta, x0, y0} /. result]

Maybe my code is too complicated for what I want, but it works so far. However now I would need to change the number by hand. For 100 images a bit annoying.

  • 1
    $\begingroup$ Have you seen the documentation for While? reference.wolfram.com/language/ref/While.html $\endgroup$
    – ktm
    Jan 25, 2018 at 13:55
  • $\begingroup$ Can you post the notebook online, maybe to dropbox or something? Or Include a code snippet? Also, is there any reason why this code has to be a notebook? It sounds like using a .wl file or a package would better suit your needs. Regardless, I don't think we can offer much advice until you update $\endgroup$
    – enano9314
    Jan 25, 2018 at 17:30
  • $\begingroup$ possible dup mathematica.stackexchange.com/q/66159/2079 (Note however that you almost certainly don't want to do that - just put all the code in one cell in a Do loop.) $\endgroup$
    – george2079
    Jan 25, 2018 at 21:42


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.