Shut down Matlab and open new Matlab instance
Afficher commentaires plus anciens
I want to close the current Matlab instance and open the new Matlab instance through Matlab command or script...Any inputs??
Réponses (3)
Srinivas
le 6 Mar 2014
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 commentaires
Rupesh
le 10 Mar 2014
Srinivas
le 10 Mar 2014
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
le 6 Mar 2014
1 vote
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 commentaires
Rupesh
le 10 Mar 2014
Andreas Goser
le 10 Mar 2014
Create a new file called finish.m. Type just the word matlab in it and save.
Sean de Wolski
le 10 Mar 2014
@Andreas, I assume you need to have the '&' after 'matlab' otherwise it will hold closing the first session until the second has closed.
Andreas Goser
le 10 Mar 2014
Maybe... I haven't tried. This is what I did probably 8y ago ;-)
Sean de Wolski
le 10 Mar 2014
system('matlab &');exit
5 commentaires
per isakson
le 18 Mar 2014
Modifié(e) : per isakson
le 18 Mar 2014
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.
Sean de Wolski
le 19 Mar 2014
I never suggested putting this in finish.m :)
per isakson
le 23 Mar 2014
Modifié(e) : per isakson
le 25 Mar 2014
@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
le 6 Fév 2018
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!
Walter Roberson
le 6 Fév 2018
system('nohup matlab 2>&1 &')
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!