利用Matlab可以很方便地对excel内的数据进行读入,并且可以将指定数据写入excel中去。
(1)读取excel数据。
- %% num = xlsread(filename, sheet, xlRange)
- A = xlsread('dataset.xlsx', 'Sheet1', 'A22:E52');
函数xlsread用来读取excel表格数据,其常用的接口函数定义和使用示例如上。
其中,‘xlRange’参数缺省时,将读入指定的‘sheet’参数页内的所有“数字数据”。
(2)向excel写入数据。
- %% xlswrite(filename, A, sheet, xlRange)
- xlswrite('dataset\dataset.xlsx',mat,'Sheet2','A2');
函数xlswrite用来向excel表格写入数据,其常用接口函数定义及示例如上。
其中,‘xlRange’表示写入数据的范围,如果不能确定,可以只赋值一个起始位置,如示例中从‘A2’位置开始写入mat数据,操作系统或自动完成其余数据的排列。