Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

open - Open file in appropriate application

Syntax

open(name)

Description

open(name) opens the specified file or variable in the appropriate application.

Inputs

name

Name of file or variable to open. If name does not include an extension, the open function:

  1. Searches for a variable named name. If the variable exists, open opens it in the MATLAB Variable Editor.

  2. Searches the MATLAB path for name.m or name.mdl. If only name.m exists, open opens the file in the M-file Editor. If only name.mdl exists, then open opens the model in Simulink.

If more than one file named name exists on the MATLAB path, the open function opens the file returned by which(name).

ExtensionAction

.m

Open in M-file Editor.

.mat

Return variables in structure st when called with the syntax:

st = open(name)

.fig

Open figure in Handle Graphics, with handle hd when called with the syntax:

hd = open(name)

.mdl

Open model in Simulink.

.prj

Open project in the MATLAB Compiler Deployment Tool.

.doc*

Open document in Microsoft Word.

.exe

Run executable file (only on Windows systems).

.pdf

Open document in Adobe® Acrobat®.

.ppt*

Open document in Microsoft PowerPoint.

.xls*

Start MATLAB Import Wizard.

.htm or .html

Open document in MATLAB browser.

.url

Open file in your default Web browser.

Extend the functionality of open by defining your own function of the form openxxx, where xxx is a file extension. For example, if you create a function openlog, the open function calls openlog to process any files with the .log extension.

Examples

Open Contents.m in the M-file Editor by typing:

open Contents.m

Generally, MATLAB opens matlabroot\toolbox\matlab\general\Contents.m. However, if you have a file called Contents.m in a directory that is before toolbox\matlab\general on the MATLAB path, then open opens that file instead. To change the path, select File > Set Path.

 

Open a file not on the MATLAB path by including the complete file specification:

open('D:\temp\data.mat')

If the file does not exist, MATLAB displays an error message.

 

Create an M-file function called opentxt to handle files with extension .txt:

function opentxt(filename)

   fprintf('You have requested file: %s\n', filename);

   wh = which(filename);
   if ~isempty(wh)
     fprintf('Opening in M-file Editor: %s\n', wh);
     edit(wh);
   elseif exist(filename, 'file') == 2
     fprintf('Opening in M-file Editor: %s\n', filename);
     edit(filename);
   else
     warning('MATLAB:fileNotFound', ...
             'File was not found: %s', filename);
   end

end  

Open the file ngc6543a.txt (a description of ngc6543a.jpg, located in matlabroot\toolbox\matlab\demos):

photo_text = 'ngc6543a.txt';
open(photo_text)

open calls your function with the following syntax:

opentxt(photo_text)

See Also

edit | fileformats | load | openfig | openvar | path | uiopen | which | winopen

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS