如何用matlab处理excel文件中的数据

 我来答
天云小店
2015-12-03 · TA获得超过2.8万个赞
知道大有可为答主
回答量:3281
采纳率:91%
帮助的人:778万
展开全部
matlab读取excel文件可用xlsread函数,向excel中写数据可用xlswrite函数。
注意:matlab不识别中文,读写的文件中最好不含有中文。

举例说明如下:
1、matlab读取excel文件数据:
bb = xlsread('c:\feature.xls', 'A0:A40');
其中:
c:\feature.xls为文件存放的地址;
A0:A40为将要读取的单元格的范围;
bb为读取的矩阵在MATLAB中的变量名。

2、matlab向excel文件写数据:
a1={'number'};
b1={'scoreA'};
c1={'scoerB'};
A=rand(100,3).*100;
xlswrite('a.xls',a1,'Sheet1','A1'); % a.xls是文件名,Sheet1是xls中第一个页面,A1为写入位置,下同
xlswrite('a.xls',b1,'Sheet1','B1');
xlswrite('a.xls',c1,'Sheet1','C1');
xlswrite('a.xls',A,'Sheet1','A2:C101');
失落世界
2015-07-02 · TA获得超过110个赞
知道答主
回答量:63
采纳率:0%
帮助的人:39.7万
展开全部
在Matlab命令行窗口使用help使用帮助命令
help xlsread
xlsread Read Microsoft Excel spreadsheet file.
[NUM,TXT,RAW]=xlsread(FILE) reads data from the first worksheet in
the Microsoft Excel spreadsheet file named FILE and returns the numeric
data in array NUM. Optionally, returns the text fields in cell array
TXT, and the unprocessed data (numbers and text) in cell array RAW.

[NUM,TXT,RAW]=xlsread(FILE,SHEET) reads the specified worksheet.

[NUM,TXT,RAW]=xlsread(FILE,SHEET,'','basic') reads from the
spreadsheet in BASIC mode, the default on systems without Excel
software.

The following syntaxes are supported only on Windows systems with Excel
software:

[NUM,TXT,RAW]=xlsread(FILE,-1) opens an Excel window to select data
interactively.

[NUM,TXT,RAW]=xlsread(FILE,RANGE) reads data from the specified
RANGE of the first worksheet in the file. Specify RANGE using the
syntax 'C1:C2', where C1 and C2 are opposing corners of the region.

[NUM,TXT,RAW]=xlsread(FILE,SHEET,RANGE) reads from the specified SHEET
and RANGE.

[NUM,TXT,RAW,CUSTOM]=xlsread(FILE,SHEET,RANGE,'',FUNCTIONHANDLE)
reads from the spreadsheet, executes the function associated with
FUNCTIONHANDLE on the data, and returns the final results. Optionally,
returns additional CUSTOM output, which is the second output from the
function. xlsread does not change the data stored in the spreadsheet.

Input Arguments:

FILE String that specifies the file to read. If you do not include
an extension, xlsread searches for a file with the specified
name and the extension '.xls'.
-1 Flag to open an interactive Excel window for selecting data.
Select the worksheet, drag and drop the mouse over the range
you want, and click OK. Supported only on Windows systems with
Excel software.
SHEET Worksheet to read. One of the following:
* String that contains the worksheet name.
* Positive, integer-valued scalar indicating the worksheet
index. Supported only on Windows systems with Excel software.
RANGE String that specifies a rectangular portion of the worksheet to
read. Not case sensitive. Use Excel A1 reference style.
If you do not specify a SHEET, RANGE must include both corners
and a colon character (:), even for a single cell (such as
'D2:D2').
'basic' Flag to request reading in basic mode, which is the default for
systems without Excel for Windows. In basic mode, xlsread:
* Only reads XLS files compatible with Excel 97-2003 software.
* Imports the entire active range of the worksheet.
* Requires a string to specify the SHEET, and the name is case
sensitive.
* Does not support function handle inputs.
FUNCTIONHANDLE
Handle to your custom function. When xlsread calls your
function, it passes a range interface from Excel to provide
access to the data. Your function must include this interface
(of type 'Interface.Microsoft_Excel_5.0_Object_Library.Range',
for example) both as an input and output argument.
从上述帮助文件可以看到相关参数及用法
例如:
假若有e:/myfile.xls文件
生日 姓名 学号

2015年7月2日 张三 8989009898
则:

读取:

filename = 'e:/myfile';%文件名
%读数值用,将数据保存到data矩阵中
data = xlsread(filename );
%若想读数值和文字信息
[data,text] = xlsread('E:\book1');

data =

8.9890e+009

text =

'生日' '姓名' '学号'
'2015-7-2' '张三' ''

写入:

xlswrite(FILE,ARRAY,SHEET,RANGE) writes to the specified SHEET and
RANGE.

在myfile.xls第一页的c4坐标写入数字1,则代码如下:

xlswrite(filename,1,1,'c4');
结果如下:
生日 姓名 学号

2015年7月2日 张三 8989009898

1
myfile.xls第一页的c4坐标写入矩阵[1,2],则代码如下:
xlswrite(filename,[1,3],1,'c4');%c4表示写入数据位置的左上角坐标,也可自己设定写入区域
结果如下:
生日 姓名 学号

2015年7月2日 张三 8989009898

1 3
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
sniperready
2015-07-02 · TA获得超过181个赞
知道小有建树答主
回答量:96
采纳率:0%
帮助的人:71.5万
展开全部
假设你的excel文件名为Example.xlsx
那么可以用下面的语句把整个表单的数据读成一个矩阵A

filename = 'Example.xlsx';
A = xlsread(filename);
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式