Main Content


Open file in appropriate application



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

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, then the open function calls openlog to process any files with the .log extension. The open function returns any single output defined by your function.

A = open(name) returns a structure if name is a MAT-file, or it returns a figure handle if name is a figure. Otherwise, open returns an empty array. For increased flexibility and options, use the load function to open MAT-files, and the openfig function to open figures.


collapse all

Open the file num2str.m in the Editor. MATLAB opens the file matlabroot\toolbox\matlab\strfun\num2str.m. If a file called num2str.m exists in a folder that is above toolbox\matlab\strfun on the MATLAB path, then MATLAB opens that file instead.

open num2str.m

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.

open C:\temp\data.mat

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

Create the function opentxt.

function opentxt(filename)
   [~, name, ext] = fileparts(filename); 
   fprintf('You have requested file: %s\n', [name ext]);

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

Create the text file myTestFile.txt.


Read the data from the file. The open function calls the function opentxt to open the file.

You have requested file: myTestFile.txt
Opening in MATLAB Editor: myTestFile.txt

Input Arguments

collapse all

File or variable name, specified as a character array or string scalar. If name does not include an extension, then MATLAB searches for variables and files according to the Function Precedence Order. If name is a variable, the open function opens it in the Variables editor. Otherwise, the open function performs one of these actions based on the file extension.

.m or .mlx

Open code file in MATLAB Editor.


Return variables in structure A when called with the syntax A = open(name).


Open figure in Figure window.

.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 report file for the Simulink cache file.

In MATLAB Online™, open only supports opening MAT-files, figures, code files (.m or .mlx), and HTML documents.

Data Types: char | string

Version History

Introduced before R2006a

See Also

| | | | |