Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
matlab reboot command?

Subject: matlab reboot command?

From: edchong Chong

Date: 28 Aug, 2009 01:57:11

Message: 1 of 4

I'm running some matlab code which eats up a lot of memory. After each iteration I need to clear the workspace. The thing is, after each iteration, the "clear" command takes a long time to execute, which is why I manually shutdown matlab (e.g. using task manager) and restart it to run the next iteration. It can take up to a few minutes for the clear command to take effect, but forcing matlab to shutdown and restart takes seconds.

Therefore, is there any way to automate this process? Like some reboot command? If not I am either forced to keep doing manual restarts, or I sacrifice a few minutes of time after each iteration.

Edmund

Subject: matlab reboot command?

From: Stan Bischof

Date: 28 Aug, 2009 03:32:00

Message: 2 of 4

edchong Chong <ilangobi@yahoo.com> wrote:
> I'm running some matlab code which eats up a lot of memory. After each
> iteration I need to clear the workspace. The thing is, after each
> iteration, the "clear" command takes a long time to execute, which is
> why I manually shutdown matlab (e.g. using task manager) and restart
> it to run the next iteration. It can take up to a few minutes for the
> clear command to take effect, but forcing matlab to shutdown and
> restart takes seconds.
>

How about a two-liner script that launches a new Matlab then exits the
current one?

Stan

Subject: matlab reboot command?

From: Aleks V

Date: 9 Oct, 2013 21:35:07

Message: 3 of 4

Stan Bischof <stan@newserve.worldbadminton.com> wrote in message <4a974fb0$0$1664$742ec2ed@news.sonic.net>...
> edchong Chong <ilangobi@yahoo.com> wrote:
> > I'm running some matlab code which eats up a lot of memory. After each
> > iteration I need to clear the workspace. The thing is, after each
> > iteration, the "clear" command takes a long time to execute, which is
> > why I manually shutdown matlab (e.g. using task manager) and restart
> > it to run the next iteration. It can take up to a few minutes for the
> > clear command to take effect, but forcing matlab to shutdown and
> > restart takes seconds.
> >
>
> How about a two-liner script that launches a new Matlab then exits the
> current one?
>
> Stan

Exit matlab? You mean taskkill /f it of course? Here is a quick hack I wrote to that end:

% Reboots matlab. Currently only works if only one instance of matlab is running.
[x, out] = system('tasklist /v /fo csv | findstr /i "matlab.exe"');
if length(strfind(out, 10)) > 1
disp('More than one instance of Matlab are running, don''t know which to kill.');
return;
end
out = out(length('"MATLAB.exe","')+1:end);
nd = strfind(out, '"');
mypid = out(1:nd(1)-1);
% Start a new instance of Matlab on a separate process in the same
% directory.
system(['start matlab.exe -sd ' pwd()]);
system(['taskkill /f /pid ' mypid]);

Subject: matlab reboot command?

From: Aleks V

Date: 9 Oct, 2013 21:45:06

Message: 4 of 4

"Aleks V" wrote in message <l34i6b$5f0$1@newscl01ah.mathworks.com>...
> Stan Bischof <stan@newserve.worldbadminton.com> wrote in message <4a974fb0$0$1664$742ec2ed@news.sonic.net>...
> > edchong Chong <ilangobi@yahoo.com> wrote:
> > > I'm running some matlab code which eats up a lot of memory. After each
> > > iteration I need to clear the workspace. The thing is, after each
> > > iteration, the "clear" command takes a long time to execute, which is
> > > why I manually shutdown matlab (e.g. using task manager) and restart
> > > it to run the next iteration. It can take up to a few minutes for the
> > > clear command to take effect, but forcing matlab to shutdown and
> > > restart takes seconds.
> > >
> >
> > How about a two-liner script that launches a new Matlab then exits the
> > current one?
> >
> > Stan
>
> Exit matlab? You mean taskkill /f it of course? Here is a quick hack I wrote to that end:
>
> % Reboots matlab. Currently only works if only one instance of matlab is running.
> [x, out] = system('tasklist /v /fo csv | findstr /i "matlab.exe"');
> if length(strfind(out, 10)) > 1
> disp('More than one instance of Matlab are running, don''t know which to kill.');
> return;
> end
> out = out(length('"MATLAB.exe","')+1:end);
> nd = strfind(out, '"');
> mypid = out(1:nd(1)-1);
> % Start a new instance of Matlab on a separate process in the same
> % directory.
> system(['start matlab.exe -sd ' pwd()]);
> system(['taskkill /f /pid ' mypid]);

Actually, scratch the above. Here is the two-liner that fits Stan's specifications:

system(['start matlab.exe -sd ' pwd()]);
system(['taskkill /f /pid ' num2str(feature('getpid'))]);

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us