Shut down Matlab and open new Matlab instance

I want to close the current Matlab instance and open the new Matlab instance through Matlab command or script...Any inputs??

답변 (3개)

Srinivas
Srinivas 2014년 3월 6일

1 개 추천

something like this
Curr_dir = pwd;
bat_str = ['"' matlabroot '\bin\matlab.exe' '"'];
fid = fopen('restart_matlab.bat','w');
fprintf(fid, '%s\n', ['cd ' Curr_dir]);
fprintf(fid, '\n%s', bat_str);
fclose(fid);
system('restart_matlab.bat')
exit
HTH

댓글 수: 2

Rupesh
Rupesh 2014년 3월 10일
Thank you Srinivas for the answer. I implemented your suggestion. Its working as per my expectations. But it is creating one .bat (restart_matlab.bat) file. Is it possible to have same functionality without generation of additional files(here, .bat file)..
Once again Thank you for the earlier reply and looking forward for the response
just delete the bat file
Curr_dir = pwd;
bat_str = ['"' matlabroot '\bin\matlab.exe' '"'];
fid = fopen('restart_matlab.bat','w');
fprintf(fid, '%s\n', ['cd ' Curr_dir]);
fprintf(fid, '\n%s', bat_str);
fclose(fid);
system('restart_matlab.bat')
delete('restart_matlab.bat')
exit

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

Andreas Goser
Andreas Goser 2014년 3월 6일

1 개 추천

In a release a couple of years ago, I created a "finish.m" on the path and within the file it was just "matlab".
When closing MATLAB, with would run finish.m and while closing MATLAB it would start another one.

댓글 수: 4

Rupesh
Rupesh 2014년 3월 10일
I am sorry but I didnt understand your text.. Could you please elaborate.. Thank you for the earlier reply..an looking forward for the response
Create a new file called finish.m. Type just the word matlab in it and save.
@Andreas, I assume you need to have the '&' after 'matlab' otherwise it will hold closing the first session until the second has closed.
Maybe... I haven't tried. This is what I did probably 8y ago ;-)

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

Sean de Wolski
Sean de Wolski 2014년 3월 10일

1 개 추천

system('matlab &');exit

댓글 수: 5

per isakson
per isakson 2014년 3월 18일
편집: per isakson 2014년 3월 18일
Warning: Do not put system('matlab &');exit in finish.m !
I did and it put my system into a loop of starting Matlab sessions. It choked the system and it was not possible to delete finish.m with the Windows Explorer. Ctrl+Alt+Del didn't work. Pushing the power button six second made it stop.
system('matlab &')
does start one new instance of Matlab.
I never suggested putting this in finish.m :)
per isakson
per isakson 2014년 3월 23일
편집: per isakson 2014년 3월 25일
@Sean, I don't blame you. I tried despite I thought it was wrong.
However, your answer together with your comment on Andreas' answer might make someone misunderstand. Thus, I think a warning is appropriate. This text might be around for years!
AA
AA 2018년 2월 6일
Hello @per,
Is there a way to do it on Linux? I tried the above command, it shows the startup screen but does not launch a new window?
Thanks!
system('nohup matlab 2>&1 &')

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2014년 3월 6일

댓글:

2018년 2월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by