Calling a Script within another script?

189 views (last 30 days)
Since a similar question is posted on the forum, I have used the command run() as one of the members of the forum said, but It seems that it doesn't work here.
I am designing a code in a script that depending on the value of flag1 and flag2 values, it calls a script or the other one. This is the code:
problem='electric'; %this must be defined by the user
if problem=='electric'
elseif problem=='mechanic'
if flag1==1
if flag2==1
When I run this script, this is the error I get:
Depending on what the user puts in the "problem" line, the code will run the script called ohm or the script called programaultimate. The script I have posted, and those two scripts (ohm and programaultimate) are saved in the same folder. Also, I have tried calling them with the .m extension with an without the run command, and it doesn't work. What am I doing wrong? How can I achieve that?
Thank you very much

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 23 Jan 2021
This you can do this way:
if flag1 == 1
if flag2 == 1
  1 Comment
ErikJon Pérez Mardaras
ErikJon Pérez Mardaras on 23 Jan 2021
Yes, I tried that and it didn't work. The reason for that is that I had a little error in the ohm script, that's why it didn't work. Now that I fixed the issue, this is the correct way of calling scripts within scripts.
Thank you!!

Sign in to comment.

More Answers (1)

Mario Malic
Mario Malic on 23 Jan 2021
Edited: Mario Malic on 23 Jan 2021
Enclose your script name in quotation marks.
Edit: with the file extension.
  1 Comment
ErikJon Pérez Mardaras
ErikJon Pérez Mardaras on 23 Jan 2021
Thanks for your reply!
If I put run("ohm") this error appears:
And if I put only "ohm", this appears on the command window but it doesn't execute the script:

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!