how to have a matlab script give you a choice to automatically open other scripts

2 views (last 30 days)
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.

Answers (1)

Les Beckham
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
Read the documentation for questdlg for more details on how you can adapt it to your preferences.
  2 Comments
juan sanchez
juan sanchez on 24 Jan 2025
Thank you very much. Just one more thing, how can I allow the secondary script to autorun so that I do not have to press run again when I run the primary script. Thank you.
Les Beckham
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

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!