Main Content

电子表格

Microsoft® Excel® 电子表格

在电子表格文件中读写数据,包括将 .xls.xlsx 中的数据写入 MATLAB® 中的表、时间表、矩阵或数组。您可以导入所选范围的数据,也可以从电子表格文件中导入多个工作表。

App

导入工具从文件导入数据

实时编辑器任务

导入数据Import data from a file in the Live Editor (自 R2023a 起)

函数

全部展开

基本导入和导出

readtable基于文件创建表
writetable将表写入文件
readtimetable基于文件创建时间表 (自 R2019a 起)
writetimetable将时间表写入文件 (自 R2019a 起)
sheetnames从电子表格文件中获取工作表名称 (自 R2019b 起)

定义导入规则

detectImportOptions基于文件内容生成导入选项
spreadsheetImportOptions电子表格的导入选项对象
getvaropts获取变量导入选项
setvaropts设置变量导入选项
setvartype设置变量数据类型
preview使用导入选项预览文件中的八行数据
readmatrix从文件中读取矩阵 (自 R2019a 起)
writematrix将矩阵写入文件 (自 R2019a 起)
readcell基于文件创建元胞数组 (自 R2019a 起)
writecell将元胞数组写入文件 (自 R2019a 起)
readvars从文件中读取变量 (自 R2019a 起)
importdata从文件加载数据

对象

spreadsheetDatastore用于电子表格文件的数据存储

主题

读取电子表格数据

  • 导入电子表格
    电子表格,(如 Microsoft Excel 文件)通常包含数值和文本数据以及变量名称和行名称的混合。在 MATLAB 中表示电子表格数据的最常见方式是使用表,但您也可以在 MATLAB 中将电子表格数据表示为时间表、矩阵或元胞数组。
  • 使用导入工具读取电子表格数据
    预览文件或剪贴板中的电子表格数据,并使用导入工具选择要导入的数据。
  • 将电子表格数据读入到表中
    在 MATLAB 中表示电子表格数据的最佳方式是表,因为表可以存储异构(数值和文本的混合)数据以及变量名称和行名称。
  • Control How MATLAB Imports Your Data
    If you want to control the import process beyond the options provided by the readtable function, such as defining how to handle missing data or errors, then create an import options object before importing the data.
  • 将电子表格数据读入数组或单个变量
    除了使用 readtable 将数据作为表导入之外,您还可以将数据作为矩阵、元胞数组导入,或将单独的变量直接导入工作区。
  • Read Collection or Sequence of Spreadsheet Files
    Read and manage data from a collection of spreadsheet files.

写入电子表格数据