文档

importdata

从文件加载数据

句法

一个= importdata(文件名)
a = importdata(' - tastepecial')
一个= importdata(___,分界符)
一个= importdata(___,,,,delimiterIn,headerlinesIn)
[a,delimiterout,headerLinesout] = importdata(___

Description

例子

一个= importdata(文件名加载s data into array一个

例子

一个= importdata(' - tastepecial')从系统剪贴板而不是从文件中加载数据。

一个= importdata(___,,,,delimiterIn解释delimiterInas the column separator in ASCII file,文件名,或剪贴板数据。您可以使用delimiterInwith any of the input arguments in the above syntaxes.

例子

一个= importdata(___,,,,delimiterIn,,,,耳线从ASCII文件加载数据,文件名,,,,or the clipboard, reading numeric data starting from line耳线+1

例子

[[一个,,,,DeLimiterout,,,,headerlinesout] = importdata(___additionally returns the detected delimiter character for the input ASCII file inDeLimiteroutand the detected number of header lines inheaderlinesout,,,,using any of the input arguments in the previous syntaxes.

Examples

collapse all

导入并显示示例图像,ngc6543a.jpg

一个= importdata('ngc6543a.jpg');图像(a)

输出,一个,是课UINT8因为辅助功能,imread,,,,returns empty results forcolormapandα

使用文本编辑器,创建一个带有列标题的空格限制的ASCII文件myfile01.txt

Day1 Day2 Day3 Day4 Day5 Day6 Day7 95.01 76.21 61.54 40.57 5.79 20.28 1.53 23.11 45.65 79.19 93.55 35.29 19.87 74.68 60.68 1.85 92.18 91.69 81.32 60.38 44.51 48.60 82.14 73.82 41.03 0.99 27.22 93.18 89.13 44.47 17.63 89.36 13.89 19.88 46.60

导入文件,指定空格定界符和单列标题。

文件名='myfile01.txt';分元='';耳线= 1; A = importdata(filename,delimiterIn,headerlinesIn);

查看第3和5列。

为了k = [3,5] disp(a.colheaders {1,k})disp(a.data(:,k))disp(''结尾
Day3 61.5400 79.1900 92.1800 73.8200 17.6300 Day5 5.7900 35.2900 81.3200 0.9900 13.8900

Using a text editor, create a comma-delimited ASCII file calledmyfile02.txt

1,2,3 4,5,6 7,8,9

Import the file, and display the output data and detected delimiter character.

文件名='myfile02.txt';[[一个,,,,DeLimiterout]=importdata(filename)
a = 1 2 3 4 5 6 7 8 9 DeLimiterout =,

将以下行复制到剪贴板。选择文本,右键单击,然后选择Copy

1,2,3 4,5,6 7,8,9

Import the clipboard data into MATLAB®by typing the following.

一个= importdata('-特殊粘贴'
一个= 1 2 3 4 5 6 7 8 9

输入参数

collapse all

Name and extension of the file to import, specified as a character vector or a string. Ifimportdatarecognizes the file extension, it calls the MATLAB helper function designed to import the associated file format (such as加载用于垫子或XLSREAD对于电子表格)。否则,importdata解释the file as a delimited ASCII file.

对于ASCII文件和电子表格,importdata期望以矩形形式找到数字数据(即矩阵)。文本标题可以显示上方或数字数据左侧,如下所示:

  • Column headers or file description text at the top of the file, above the numeric data.

  • 数字数据左侧的行标头。

Example:'myfile.jpg'or“ myfile.jpg”

数据类型:char|细绳

列分离器字符,指定为字符向量或字符串。默认字符是从文件中解释的。利用'\ t'对于选项卡。

Example:','or“,”

Example:''or" "

数据类型:char|细绳

Number of text header lines in the ASCII file, specified as a nonnegative scalar integer. If you do not specify耳线, 这importdata函数在文件中检测该值。

数据类型:单身的|double|int8|int16|int32|INT64|UINT8|uint16|UINT32|Uint64

输出参数

collapse all

文件中的数据,根据文件的特征,以矩阵,多维数组或标量结构数组返回。基于输入文件的文件格式,importdatacalls a helper function to read the data. When the helper function returns more than one nonempty output,importdata将输出结合到一个结构大批。

该表列出了与帮助助手函数关联的文件格式,这些函数可以返回多个输出,以及结构数组中的可能字段,一个

文件格式 可能的字段 班级

MAT-files

One field for each variable

与每个变量关联。

ASCII文件和电子表格

data
textdata
科尔黑头
rowheaders

对于ASCII文件,data包含adouble大批。其他字段包含cellarrays of character vectors.textdata包括行和列标题。
对于电子表格,每个字段都包含一个结构,每个工作表都有一个字段。

图片

cdata
colormap
α

imread

音频文件

data
FS

audioread

The MATLAB helper functions for most other supported file formats return one output. For more information about the class of each output, see the functions listed in金宝app支持进口和导出的文件格式

如果ASCII文件或电子表格包含列或行标头,但不两个,但不两个,importdata返回a科尔黑头orrowheadersfield in the output structure, where:

  • 科尔黑头contains only the last line of column header text.importdata将所有文本存储在textdata场地。

  • rowheaders仅当文件或工作表包含一个行标头的单列时创建。

在输入ASCII文件中检测到的列分离器,作为字符向量返回。

Detected number of text header lines in the input ASCII file, returned as an integer.

Tips

  • 要在列或行标头外用非数字字符导入ASCII文件,包括字符数据或格式日期或时间的列,请使用textscan代替importdata

Introduced before R2006a

Was this topic helpful?