This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Open file in appropriate application


output = open(name)


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

output = open(name) returns an empty output ([]) for most cases. If opening a MAT-file, output is a structure that contains the variables in the file. If opening a figure, output is a handle to that figure.

Input Arguments


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 Variables editor.

  2. Searches the MATLAB® path for name.mdl, name.slx, name.mlx or name.m. If name.mdl or name.slx exists, then open opens the model in Simulink®. If name.mlx or name.m exists, then open opens the code file in the MATLAB Editor.

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

The open function performs the following actions based on the file extension:

.m or .mlx

Open code file in MATLAB Editor.


Return variables in structure st when called with the syntax:

st = open(name)


Open figure in Handle Graphics®.

.mdl or .slx

Open model in Simulink.


Open project in the MATLAB Compiler Deployment Tool.


Open document in Microsoft® Word.


Run executable file (only on Windows® systems).


Open document in Adobe® Acrobat®.


Open document in Microsoft PowerPoint®.


Start MATLAB Import Wizard.

.htm or .html

Open document in MATLAB browser.


Open file in your default Web browser.


Open Contents.m in the MATLAB 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.

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


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

Create a function called opentxt to handle files with extension .txt:

function opentxt(filename)

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

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


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

photo_text = 'ngc6543a.txt';

open calls your function with the following syntax:


More About

collapse all


The open function opens files based on their extension. You can extend the functionality of open by defining your own file handling 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. The open function returns any single output defined by your function.

Introduced before R2006a

Was this topic helpful?