| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
open(name)
open(name) opens the specified file or variable in the appropriate application.
name |
Name of file or variable to open. If name does not include an extension, the open function:
If more than one file named name exists on the MATLAB path, the open function opens the file returned by which(name).
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. |
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)
edit | fileformats | load | openfig | openvar | path | uiopen | which | winopen
![]() | ones | openfig | ![]() |

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 |