Calling a Script within another script?
434 ビュー (過去 30 日間)
古いコメントを表示
ErikJon Pérez Mardaras
2021 年 1 月 23 日
編集済み: Mario Malic
2021 年 1 月 23 日
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:
flag1=0;
flag2=0;
problem='electric'; %this must be defined by the user
if problem=='electric'
flag1=1;
elseif problem=='mechanic'
flag2=1;
end
if flag1==1
run(ohm)
end
if flag2==1
run(programaultimate)
end
When I run this script, this is the error I get:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/497632/image.png)
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
0 件のコメント
採用された回答
Bjorn Gustavsson
2021 年 1 月 23 日
This you can do this way:
if flag1 == 1
ohm
end
if flag2 == 1
programaultimate
end
HTH
その他の回答 (1 件)
Mario Malic
2021 年 1 月 23 日
編集済み: Mario Malic
2021 年 1 月 23 日
Enclose your script name in quotation marks.
Edit: with the file extension.
run("ohm.m")
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!