필터 지우기
필터 지우기

Executing independent scripts sequentially

조회 수: 65 (최근 30일)
lp18692
lp18692 2018년 11월 21일
댓글: lp18692 2018년 11월 21일
Hello everyone,
I have a script that calls several other scripts with the 'run' command:
run('script1.m');
run('script2.m');
run('script3.m');
However, I think script2 is executed as soon as script1 has started. This can cause some problems, eg if both scripts have control variables of the same name. What I want is for MATLAB to wait until script1 finishes before running script2. I don't want to make the scripts into functions because I have to run them on their own sometimes.
What would be the best way to do this?
Thanks!

채택된 답변

Cris LaPierre
Cris LaPierre 2018년 11월 21일
This should work. What if you just call the scripts by name instead of using the run command?
% other code
script1
script2
script3
% rest of this script
Look through the advice in this post to see if that helps.
  댓글 수: 1
lp18692
lp18692 2018년 11월 21일
That does the trick. I don't know why I was bothering with 'run'...
Thanks a lot!

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

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 11월 21일
P.S - Just a try
for i =1:3
s(i)=sprintf('script%d',i)
if s(i)==l %add l=2 to the end of each script to make sure the script is finished and then the next script executes
continue
end
end

카테고리

Help CenterFile Exchange에서 Manage Products에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by