1.使用函数xlsread读取单个文件(1)num=xlsread(filename)(2)num = xlsread(file" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > <em>Matlab</em>怎么读取excel文件里含有字母和数字的数据?-matlab ex

<em>Matlab</em>怎么读取excel文件里含有字母和数字的数据?-matlab ex

作者:乔山办公网日期:

返回目录:excel表格制作




1.使用函数xlsread读取单个文件
(1)num=xlsread(filename)
(2)num = xlsread(filename, -1)
(3)num = xlsread(filename, sheet)
(4)num = xlsread(filename,sheet, 'range')

例如:

将读取D盘下copy的一个文件路径为:D:/test/daxia.xls
num = xlsread('d:/test/daxia.xls',2,'D2:H4')读取sheet2的D2:H4区域数据
如果要进行交互式的选择用:num = xlsread('d:/test/daxia.xls',-1)


2.批量的文zd件要读取
首先将多个文件进行批量重命名
然后用循环的方式实现:
for i=1:100
filename=['d:/test/daxia',num2str(i),'.xls']; 
num=xlsread(filename)
end


用函数xlsread:
读取命令:[data,text] = xlsread(FileName, SheetName, Range);
data保存的是数据单元格的值, text保存的是字符串单元格的内容。
例如:[data,text] = xlsread('C:\Test\test.xlsx'', 'sheet1', 'A2:D10');
存储方式为矩阵,和Excel表格中的位置一致。
如果Sheet内都是数据,可直接使用data = xlsread(文件名)。

情形一:读取Excel文件

1
如果数据文件为excel文件(xls或者xlsx格式的文件),如下图所示的数据文件

2
我们只需要使e799bee5baa6e79fa5e98193e58685e5aeb9366用MATLAB中提供的系统函数xlsread函数即可,其主要的调用形式为:
a=xlsread('filename.xls');
其中a表示读入文件所保存的变量名称,filename.xls(或者filename.xlsx)表示excel数据文件,help帮助文档中对xlsread函数的介绍如下图所示:

3
对于上图所示的数据文件,我们只需要使用下面的命令进行读取即可:
A = xlsread('data.xlsx');

4
如果数据文件保存在excel的某个sheet中,我们的使用方式为:
A = xlsread('data.xlsx','Sheet1');
END
情形二:写入Excel文件

如果需要把某个变量的存储的数据写入到excel文件(xls或者xlsx格式的文件),如下图所示的变量

我们只需要使用MATLAB中提供的系统函数xlswrite()函数即可,其主要的调用形式为:
xlswrite('filename.xls',variable);
其中variable表示需要写入Excel文件的变量名称,filename.xls(或者filename.xlsx)表示excel数据文件,help帮助文档中对xlswrite()函数的介绍如下图所示:

对于上图所示的数据文件,我们只需要使用下面的命令进行读取即可:
xlswrite('output.xlsx',A);

4
Excel数据文件如下图所示:

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网