Desktop Tools and Development Environment Previous page   Next Page

Opening and Running Files

Opening Files

You can open a file from the Current Directory browser and the file opens in the tool associated with that file type.

To open a file, select one or more files and perform one of the following actions:

The file opens in the appropriate tool. For example, the Editor/Debugger opens for M-files, and Simulink opens for model (.mdl) files.

To open a file in the Editor/Debugger, no matter what type it is, select Open as Text from the context menu. One exception is P-files (.p), which you cannot open.

To open a file using an external application, select Open Outside MATLAB from the context menu. For example, if you select myfile.doc, Open Outside MATLAB opens myfile.doc in Microsoft Word, assuming you have the .doc file association configured to start Word.

You can also import data from a file. Select the file, right-click, and select Import Data from the context menu. The Import Wizard opens. See the Import Wizard documentation for instructions to import the data.

Function Alternative.   Use the open function to open a file in the tool appropriate for the file, given its file extension. Default behavior is provided for standard MATLAB file types. You can extend the interface to include other file types and to override the default behavior for the standard files. For name.ext, open performs the following actions.

File Type
Extension
Action  
Figure file
fig
Opens figure name.fig in a figure window.
HTML file
html
Opens HTML file name.html in the MATLAB Web browser.
M-file
m
Opens M-file name.m in the Editor/Debugger.
MAT-file
mat
Opens MAT-file name.mat in the Import Wizard.
Model
mdl
Opens model name.mdl in Simulink.
P-file
p
Cannot open P-files (pseudocode files that do not expose the M-file code.
PDF file
pdf
Opens the PDF file name.pdf in the installed PDF reader, for example, Adobe Acrobat.
Variable
none
Opens the numeric or string array name in the Array Editor; open calls openvar.
Other
custom
Opens name.custom by calling the helper function opencustom, where opencustom is a user-defined function.

Use winopen to open a file using an external application on Windows platforms.

To view the content of an ASCII file, such as an M-file, use the type function. For example

type('startup')

displays the contents of the file startup.m in the Command Window.

Running M-Files

To run an M-file from the Current Directory browser, select it, right-click, and select Run from the context menu. The results appear in the Command Window.


Previous page  Creating, Renaming, Copying, and Removing Directories and Files Finding Files and Content Within Files Next page

© 1994-2005 The MathWorks, Inc.