- You have a script. Lets call it myScript.
- The first line of myScript is clear all
- Near the top of myScript there is an assignment, e.g input = 17;.
- In myScript a result is assigned to a variable, e.g. output = expression;
- Now you want to run myScript with different values, e.g. [2,3,5,7,11,13,17], of the variable, input

- In myScript comment out the lines clear all and input = 17; Result: % clear all and % input = 17;
- Create a script in a new file, e.g. loop_over_myScript

- Beg that no variables named, vector, vec or out_vector, exist in myScript. (Renaming them vector__, vec__ and out_vector__ might decrease the risk of name collision.)
- Run loop_over_myScript
- Inspect out_vector, e.g with the Variables Editor
- Run whos and be horrified by all the variables that litters the base workspace.

## 8 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714682

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714682

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714686

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714686

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714692

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714692

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714702

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714702

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714708

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714708

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714757

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714757

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714784

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714784

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714924

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/467061-how-can-i-run-a-matlab-program-n-times-using-a-different-value-of-one-of-my-variables#comment_714924

Sign in to comment.