fileread
以文本格式读取文件内容
说明
示例
输入参数
filename
— 要读取的文件的名称
字符向量或字符串标量
要读取的文件的名称,指定为包含文件扩展名的字符向量或字符串标量。fileread
利用自动字符集检测来确定文件编码。
在 UNIX® 系统上,如果 filename
以 '~/'
或 '~
开头,则 username
/'fileread
函数分别延长路径至当前用户或指定用户的主目录。
根据文件的位置,filename
可以采用下列形式之一。
当前文件夹或 MATLAB® 路径上的文件夹 | 指定 如要打开有读取权限的文件而该文件不在当前文件夹中,则 示例: | ||||||||
其他文件夹 | 如果该文件不在当前文件夹或 MATLAB 路径下的文件夹中,则在 示例: 示例: | ||||||||
远程位置 | 如果文件存储在远程位置,则
根据您的远程位置,
如果您使用的是云文件系统,请设置环境变量以与远程文件系统通信。有关详细信息,请参阅处理远程数据。 示例: |
示例: 'myFile.dat'
数据类型: char
| string
encoding
— 字符编码方案
""
| "UTF-8"
| "ISO-8859-1"
| "windows-1251"
| "windows-1252"
| ...
与文件关联的字符编码方案,指定为 ""
或标准字符编码方案名称,如下表所示的值之一。当您未指定任何编码或将编码指定为 ""
时,fileread
函数使用默认 MATLAB 编码来读取文件。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
示例: Encoding="system"
使用系统默认编码。
扩展功能
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
用法说明和限制:
如果函数
fileread
读取整个文件,则所有数据都必须能够放入可供代码生成使用的最大数组中。fileread
函数的代码生成器将源或输出的字符值视为有符号 8 位整数。只能使用 0 到 127 之间的值。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
版本历史记录
在 R2006a 之前推出R2022b: 在基于线程的环境中使用函数
此函数支持基于线程的环境。
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)