| MATLAB Function Reference | ![]() |
open('name')
open('name') opens the object specified by the string name. The specific action taken upon opening depends on the type of object specified by name.
name | Action |
|---|---|
DOC file (*.doc) | Open document in Microsoft® Word application. |
EXE file (*.exe) | Run Microsoft Windows® executable file. |
Figure file (*.fig) | Open figure in a MATLAB® figure window. |
HTML file (*.html, *.htm) | Open HTML document in a separate window. |
M-file (name.m) | Open M-file name in M-file Editor. |
MAT-file (name.mat) | Open MAT-file and store variables in a structure in the workspace. |
Model (name.mdl) | Open model name in Simulink® application. |
P-file (name.p) | Open the corresponding M-file, name.m, if it exists, in the M-file Editor. |
PDF file (*.pdf) | Open PDF document in Adobe® Acrobat® application. |
PPT file (*.ppt) | Open document in Microsoft PowerPoint® application. |
Project file (*.prj) | Open the project file in the MATLAB Compiler Deployment Tool. If the MATLAB Compiler or Deployment Tool is not installed, open the project file in a text editor. |
URL file (*.url) | Open an Internet location in your default Web browser |
Variable | Open array name in the Array Editor (the array must be numeric). |
Other extensions (name.xxx) | Open name.xxx by calling the helper function openxxx, where openxxx is a user-defined function. |
No extension (name) | Open name in the default editor. If name does not exist, then open checks to see if name.mdl or name.m is on the path or in the current directory and, if so, opens the file returned by which('name'). |
If more than one file with the specified filename name exists on the MATLAB path, then open opens the file returned by which('name').
If no such file name exists, then open displays an error message.
You can create your own openxxx functions to set up handlers for new file types. This does not apply to the file types shown in the table above. open('filename.xxx') calls the openxxx function it finds on the path. For example, create a function openlog if you want a handler for opening files with file extension .log.
To open the M-file copyfile.m, type
open copyfile.m
MATLAB opens the copyfile.m file that resides in toolbox\matlab\general. If you have a copyfile.m file in a directory that is before toolbox\matlab\general on the MATLAB path, then open opens that file instead.
To open a file that is not on the MATLAB path, enter the complete file specification. If no such file is found, then MATLAB displays an error message.
open('D:\temp\data.mat')When you specify a file without including its file extension, MATLAB determines which file to open for you. It does this by calling
which('filename')In this example, open matrixdemos could open either an M-file or a Simulink model of the same name, since both exist on the path.
dir matrixdemos.* matrixdemos.m matrixdemos.mdl
Because the call which('matrixdemos') returns the name of the Simulink model, open opens the matrixdemos model rather than the M-file of that name.
open matrixdemos % Opens model matrixdemos.mdl
This example opens a MAT-file containing MATLAB data and then keeps just one of the variables from that file. The others are overwritten when ans is reused by MATLAB.
% Open a MAT-file containing miscellaneous data.
open D:\temp\data.mat
ans =
x: [3x2x2 double]
y: {4x5 cell}
k: 8
spArray: [5x5 double]
dblArray: [4x1 java.lang.Double[][]]
strArray: {2x5 cell}
% Keep the dblArray value by assigning it to a variable.
dbl = ans.dblArray
dbl =
java.lang.Double[][]:
[ 5.7200] [ 6.7200] [ 7.7200]
[10.4400] [11.4400] [12.4400]
[15.1600] [16.1600] [17.1600]
[19.8800] [20.8800] [21.8800]If you create an M-file function called opencht to handle files with extension .cht, and then issue the command
open myfigure.cht
open calls your handler function with the following syntax:
opencht('myfigure.cht')edit, load, save, saveas, uiopen, which, file_formats, path
![]() | ones | openfig | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |