3

I want to shutdown my computer in matlab scripts when the program has ran to end. Is there any commands about this?

1
  • What operating system? Commented Oct 8, 2013 at 10:01

2 Answers 2

7

This should work: system('shutdown -s');

You can also try the following function as posted in Matlab Central.

function shutdown(varargin)
if nargin
   if isnumeric(varargin{1})
       if varargin{1} == -1
           evalc('!shutdown -a');
           return
       end
       t = ceil(varargin{1});
    else
       t = 60;
    end
else
   t = 60;
end
eval(['!shutdown -s -f -t ' num2str(t)])

USAGE:

  • shutdown = turn off the computer in 60 seconds
  • shutdown(numsec) = turn off the computer in numsec seconds
  • shutdown(-1) = abort the shutdown; don't turn off the computer
  • numsec = optional number of seconds to pause after system shutdown window is displayed (defualt is 60 seconds). If numsec is -1, then the command aborts a shutdown countdown currently in progress.
Sign up to request clarification or add additional context in comments.

Comments

2

This one should work on windows, linux and mac. However your matlab should be running under a superuser/adminsitrator account

if ispc
    !shutdown -s -f -t 0
else
    !shutdown -h now
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.