Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

导入工具

从文件导入数据

说明

通过导入工具,您可以从电子表格文件、分隔文本文件和等宽的文本文件中预览和导入数据。在 MATLAB® Online™ 中,您还可以预览和导入 netCDF 文件中的数据。您能够以交互方式选择要导入的数据并重用工具生成的脚本或函数以导入其他类似文件。

Import Tool

打开 导入工具

  • MATLAB 工具条:在主页选项卡中的变量部分中,点击导入数据

  • MATLAB 命令提示符:输入 uiimport(filename),其中 filename 是用于指定文本或电子表格文件(或 MATLAB Online 中的 netCDF 文件)名称的字符向量。

示例

全部展开

从制表符分隔的文本文件导入某些范围的数据,并替换文件中的非数值数据。

拖动光标以选择要导入的元胞。按 Ctrl 以选择不连续的范围。

Preview of text data import in the Import Tool. Some data elements are selected, and the Output Type field is set to Column vectors.

修改变量名称行字段,以指示您希望导入工具用于变量名称的行。

Preview of text data import in the Import Tool. The Variable Names Row field is set to 3. The variable names are the values in the third row of data: CH1, CH2, and CH3.

默认情况下,NaN 会替换数值元胞中无法导入的值。不过,您可以将此值更改为任何其他数值。在导入选项卡上的无法导入的元胞部分,指定如何处理无法导入的值。

Preview of text data import in the Import Tool. Unimportable cells are highlighted in yellow and are replaced with the value -99.0.

或者,从导入中排除包含无法导入的元胞的行。

Import Tool setting for text data import. Rows with unimportable cells are highlighted in purple and are excluded from the import.

点击导入所选内容按钮 。新的列向量出现在您的工作区中。

Workspace containing column vectors CH1 and CH3

将文本文件中的日期和数字导入一个表中。为文件中的数值指定小数分隔符,为日期指定自定义格式。

导入的数据部分中,选择以将文件数据导入一个 table 变量中。在此示例中,数据的第三列包含货币金额,其中的小数分隔符为逗号。在分隔符部分,选择分隔符选项。然后,在小数分隔符下,选择 , (逗号)

导入工具会适当地转换货币值。

Import Tool settings. The Output Type field is set to Table, and the Delimiter Options field is set to a comma decimal separator.

将某列的数据类型更改为日期/时间,指定该列包含日期或时间数据。点击更多日期格式...。向下滚动列表以输入自定义日期格式。

List of Import Tool options for date and time formats. There is a text field to apply a custom date format to the selected data.

点击导入所选内容按钮 以导入表。

相关示例

编程用途

全部展开

uiimport 打开一个对话框,以交互方式从文件或剪贴板中加载数据。MATLAB 显示文件中的数据的预览。

根据文件类型,uiimport(filename) 使用导入工具导入向导打开 filename 中指定的文件。对于电子表格和文本文件(以及 MATLAB Online 中的 netCDF 文件),uiimport 使用导入工具打开文件。对于所有其他文件类型,如图像、音频或 MAT 文件,uiimport 使用导入向导打开文件。

uiimport('-file') 首先显示文件选择对话框。

uiimport('-pastespecial') 首先显示剪贴板内容。

S = uiimport(___) 使用导入向导打开文件,并以字段形式将生成的变量存储在结构体 S 中。

版本历史记录

全部展开

另请参阅

函数

实时编辑器任务