在matlab中导入excel中的数据,EXCEL中的数据如何导入matlab

XLSREAD是MATLAB中用于从Excel工作簿读取数据的函数。它可以返回数值、文本和原始数据。根据提供的文件路径、工作表名和范围,用户可以选择性地读取特定区域的数据。当Excel可用作COM服务器时,可以使用自定义函数进行更复杂的操作,例如在读取数据前转换单元格格式。在不支持COM服务器的平台上,只能使用基本模式,可能无法选择特定范围。
摘要由CSDN通过智能技术生成

help xlsread

还给了这么多的例子

XLSREAD Get data and text from a spreadsheet in an Excel workbook.

[NUMERIC,TXT,RAW]=XLSREAD(FILE) reads the data specified in the Excel

file, FILE. The numeric cells in FILE are returned in NUMERIC, the text

cells in FILE are returned in TXT, while the raw, unprocessed cell

content is returned in RAW.

[NUMERIC,TXT,RAW]=XLSREAD(FILE,SHEET,RANGE) reads the data specified

in RANGE from the worksheet SHEET, in the Excel file specified in FILE.

It is possible to select the range of data interactively (see Examples

below). Please note that the full functionality of XLSREAD depends on

the ability to start Excel as a COM server from MATLAB.

[NUMERIC,TXT,RAW]=XLSREAD(FILE,SHEET,RANGE,'basic') reads an XLS file as

above, using basic input mode. This is the mode used on UNIX platforms

as well as on Windows when Excel is not available as a COM server.

In this mode, XLSREAD does not use Excel as a COM server, which limits

import ability. Without Excel as a COM server, RANGE will be ignored

and, consequently, the whole active range of a sheet will be imported.

Also, in basic mode, SHEET is case-sensitive and must be a string.

[NUMERIC,TXT,RAW]=XLSREAD(FILE,SHEET,RANGE,'',CUSTOMFUN)

[NUMERIC,TXT,RAW,CUSTOMOUTPUT]=XLSREAD(FILE,SHEET,RANGE,'',CUSTOMFUN)

When the Excel COM server is used, allows passing in a handle to a

custom function.  This function will be called just before retrieving

the actual data from Excel. It must take an Excel Range object (e.g. of

type 'Interface.Microsoft_Excel_5.0_Object_Library.Range') as input,

and return one as output.  Optionally, this custom function may return

a second output argument, which will be returned from XLSREAD as the

fourth output argument, CUSTOMOUTPUT.  For details of what is possible

using the EXCEL COM interface, please refer to Microsoft documentation.

INPUT PARAMETERS:

FILE: string defining the file to read from. Default directory is pwd.

Default extension is 'xls'.

SHEET: string defining worksheet name in workbook FILE.

double scalar defining worksheet index in workbook FILE. See

NOTE 1.

RANGE: string defining the data range in a worksheet. See NOTE 2.

MODE: string enforcing basic import mode. Valid value = 'basic'.

RETURN PARAMETERS:

NUMERIC = n x m array of type double.

TXT = r x s cell string array containing text cells in RANGE.

RAW = v x w cell array containing unprocessed numeric and text data.

Both NUMERIC and TXT are subsets of RAW.

EXAMPLES:

1. Default operation:

NUMERIC = xlsread(FILE);

[NUMERIC,TXT]=xlsread(FILE);

[NUMERIC,TXT,RAW]=xlsread(FILE);

2. Get data from the default region:

NUMERIC = xlsread('c:\matlab\work\myspreadsheet')

3. Get data from the used area in a sheet other than the first sheet:

NUMERIC = xlsread('c:\matlab\work\myspreadsheet','sheet2')

4. Get data from a named sheet:

NUMERIC = xlsread('c:\matlab\work\myspreadsheet','NBData')

5. Get data from a specified region in a sheet other than the first

sheet:

NUMERIC = xlsread('c:\matlab\work\myspreadsheet','sheet2','a2:j5')

6. Get data from a specified region in a named sheet:

NUMERIC = xlsread('c:\matlab\work\myspreadsheet','NBData','a2:j5')

7. Get data from a region in a sheet specified by index:

NUMERIC = xlsread('c:\matlab\work\myspreadsheet',2,'a2:j5')

8. Interactive region selection:

NUMERIC = xlsread('c:\matlab\work\myspreadsheet',-1);

You have to select the active region and the active sheet in the

EXCEL window that will come into focus. Enter any letter at Matlab

command line when finish selecting the active region.

9. Using the custom function:

[NUMERIC,TXT,RAW,CUSTOMOUTPUT] = xlsread('equity.xls', ..., @MyCustomFun)

Where the CustomFun is defined as:

function [DataRange, customOutput] = MyCustomFun(DataRange)

DataRange.NumberFormat = 'Date';

customOutput = 'Anything I want';

This will convert to dates all cells where that is possible.

NOTE 1: The first worksheet of the workbook is the default sheet. If

SHEET is -1, Excel comes to the foreground to enable interactive

selection (optional). In interactive mode, a dialogue will prompt

you to click the OK button in that dialogue to continue in MATLAB.

(Only supported when Excel COM server is available.)

NOTE 2: The regular form is: 'D2:F3' to select rectangular region D2:F3

in a worksheet. RANGE is not case sensitive and uses Excel A1

notation (see Excel Help). (Only supported when Excel COM server

is available.)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值