how to have a matlab script give you a choice to automatically open other scripts
2 views (last 30 days)
Show older comments
Hi, I want to have a starting script where it allows me to open a different script. For example I want the main script to ask me, do you wish to follow procedure A? and then if I select yes, then automatically the matlab will open script A. If the main script asks, do you wish procedure B? then Matlab opens automatically script B and so on. Then once in the secondary script, I will enter the parameters needed to perform the calculation. Thank you.
0 Comments
Answers (1)
Les Beckham
on 23 Jan 2025
Edited: Les Beckham
on 23 Jan 2025
That seems like a questionable workflow. Nevertheless, this should get you started.
% StartingScript.m
response = questdlg('Open ScriptA?');
if strcmp(response, 'Yes')
edit('ScriptA.m')
end
% and so on
2 Comments
Les Beckham
on 25 Jan 2025
Edited: Les Beckham
on 25 Jan 2025
I'm not sure I understand what you mean by "autorun".
Are you running the "primary script" in a loop and you want the selection of the secondary script to be repeated each time after the initial selection of which "secondary script" was made?
Your question is quite vague. More detail of what you are really trying to do would help.
In general, using scripts (especially for something that you want to run more than once) is bad practice.
If you have some processing that you want to do more than once with different inputs (data), you should use functions instead of scripts. I suggest that you read this help page Scripts vs. Functions.
Also, if you are just getting started with Matlab, I would highly recommend that you take a couple of hours to go through the free online tutorial: Matlab Onramp
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!