How to run scripts (not functions) with predefined user inputs?

조회 수: 37(최근 30일)
Vugar 2017년 9월 12일
편집: José-Luis 2017년 9월 12일
There are several scripts in MATLAB with some user inputs (for example, x=input('Enter x: ')). The scripts cannot be executed automatically, since they require to manually define all user inputs. The only way I know to automatically execute the script with predefined inputs is by using pop-up history: I run script once, defining all inputs, and the next time I can simply highlight and launch the script with the previously defined inputs from pop-up history. The drawback of the descibed technique is that I cannot run the script with the predefined inputs from any other place (for example, I want to repeatedly run the script with predefined inputs from another script or function).
Does anybody know a solution differing from using matlab history?


José-Luis 2017년 9월 12일
  댓글 수: 2
José-Luis 2017년 9월 12일
편집: José-Luis 2017년 9월 12일
Like Stephen said, use a function, that's what they're for.
Make your script a function. Any other solution is just a kludge.
A function can call other functions and/or scripts. Encapsulation will preserve your sanity so learn to use it.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by