open
在合适的应用程序中打开文件
说明
open
在适当的应用程序中打开指定的文件或变量。name
您可以通过 open
的形式(其中 xxx
xxx
为文件扩展名)定义您自己的文件处理函数,以此扩展 open
的功能。例如,如果您创建了函数 openlog
,则 open
函数将调用 openlog
来处理带有 .log
扩展名的任何文件。open
函数将返回您的函数所定义的任何单个输出。
示例
打开文件
在编辑器中打开文件 num2str.m
。MATLAB 会打开文件 matlabroot
\toolbox\matlab\strfun\num2str.m
。但是,如果在 MATLAB 路径中 toolbox\matlab\strfun
之上的文件夹中存在名为 num2str.m
的文件,MATLAB 将打开该文件。
open num2str.m
打开不在路径中的文件
通过指定文件的完整路径,可打开不在 MATLAB® 路径中的文件。如果文件不存在,MATLAB 将显示错误消息。
open C:\temp\data.mat
创建处理扩展名的函数
创建名为 opentxt
的函数,以处理具有 .txt
扩展名的文件。
创建函数 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]); edit(filename); else wh = which(filename); if ~isempty(wh) fprintf('Opening in MATLAB Editor: %s\n', wh); edit(wh); else warning('MATLAB:fileNotFound', ... 'File was not found: %s', [name ext]); end end end
创建文本文件 myTestFile.txt
。
dlmwrite('myTestFile.txt',[1,2,3,4]);
读取该文件中的数据。open
函数将调用函数 opentxt
来打开该文件。
open('myTestFile.txt');
You have requested file: myTestFile.txt Opening in MATLAB Editor: myTestFile.txt
输入参数
name
— 文件或变量的名称
字符数组 | 字符串标量
文件或变量的名称,指定为字符向量或字符串标量。如果 name
不包含扩展名,MATLAB 将根据函数优先顺序来搜索变量和文件。如果 name
是变量,open
函数将在变量编辑器中打开它。否则,open
函数将根据文件扩展名执行以下操作之一。
| 在 MATLAB 编辑器中打开代码文件。 |
| 使用语法 |
| 在图窗窗口中打开图窗。 |
| 在 Simulink® 中打开模型。 |
| 在 MATLAB Compiler 部署工具中打开工程。 |
| 在 Microsoft® Word 中打开文档。 |
| 运行可执行文件(仅在 Windows® 系统上)。 |
| 在 Adobe® Acrobat® 中打开文档。 |
| 在 Microsoft PowerPoint® 中打开文档。 |
| 启动 MATLAB 导入向导。 |
| 在 MATLAB 浏览器中打开文档。 |
| 打开 Simulink 缓存文件的报告文件。 |
在 MATLAB Online™ 中,open
仅支持打开 MAT 文件、图窗、代码文件(.m
或 .mlx
)和 HTML 文档。
数据类型: char
| string
版本历史记录
在 R2006a 之前推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)