0

I tried to close a file(pdf,ppt,txt,..etc) or a browser after opening it using the open or winopen command using Matlab but could not find any such function to close them. So, how can one do it?

ajj114
  • 3
  • 3
  • 2
    See here: http://de.mathworks.com/matlabcentral/answers/100196-how-do-you-close-a-document-once-it-has-been-opened-using-winopen-in-matlab-7-1-r14sp3, and here: http://www.mathworks.com/matlabcentral/answers/55013-any-application-closing-using-matlab – scmg Apr 02 '15 at 13:31
  • visit 1->http://in.mathworks.com/help/matlab/ref/fclose.html visit 2->http://stackoverflow.com/questions/5222238/how-to-close-file-handle-in-matlab – Sagar Naliyapara Apr 02 '15 at 13:32

3 Answers3

3

That's not possible. open will let your operating system decide which program to run in order to display the file you want; there's no communication between matlab and that program happening.

Closing a program, on the other hand, needs communication. Matlab doesn't know how to instruct PowerPoint, your PDF reader, your browser, your text viewer to close their window, because all programs are somewhat different there. There's surely a way to simulate a "user clicked the close window button" win32 signal, but really, that's not something you want to do from matlab.

Marcus Müller
  • 31,250
  • 4
  • 47
  • 86
2

There is no such function because there is no standard way to do it. You have to check the documentation for the program which opens the file, if such a possibility exists.

For files which are supported by web, concider using the matlab web browser:

%open txt in matlab web browser
[stat,h] = web('example.txt')
%close it
close(h)
Daniel
  • 36,282
  • 3
  • 33
  • 67
2

You can use the dos command taskkill - but beware it might close more things that you expect and could cause you to lose unsaved data.

matlabgui
  • 5,497
  • 1
  • 11
  • 15