怎么把excel中的数据导入matlab中?

我用matlab菜单file中的important data直接导入excel,excel中的汉字和数据都以字符形式存入到textdata中了,这样就不能进行矩阵的各种运算了,请问如何正确导入数据,并且导入后是以数字形式出现。初学matlab,有很多东西都不懂,盼高手指教。

第一种方法,你可以使用xlsread函数来读取excel中的数据

第二种方法,就是把字符转化为数字,使用函数str2num

xlsread的使用
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. Click OK in the Data
Selection Dialog when you have finished selecting the active region.

祝你学习愉快!
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-03-01
选择“open file”,即 file中的“open ",就会出现一个对话框,先把对话框的最下面“文件类型”选择“All files”,再在“查找范围”的下拉框里选择你要导入的excel数据,单击“打开”就会出现一个matlab的对话框,单击“finish”就行了。此时在matlab的窗口中的“workspace”里面就存有你要的数据了。追问

这样和我原来用的方法是一样的,得到的数据还是字符形式,而不是数字,也就是你输入textdata得到的矩阵的元素全部都是字符,不能进行矩阵运算的。每个元素上都有' ',或者告诉我怎么把这些字符型的转化为double型的数据也可以。

第2个回答  2018-04-12

excel中的数据导入matlab中的方法:

1、你可以使用xlsread函数来读取excel中的数据

2、就是把字符转化为数字,使用函数str2num

xlsread的使用:

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. Click OK in the Data ,

Selection Dialog when you have finished selecting the active region。

本回答被网友采纳
第3个回答  2020-02-11
第4个回答  2011-03-01
readxls追问

其实我发现了一个比较简单的方法,就是把excel中的数据改成数字格式,因为是成绩单,所以原来存储的时候为了保证学号前面的0能够出现,都存储成了文本格式,改过之后,再按照原来的导入就可以了。文本格式导入后是存在了textdata中,而数字格式导入后是存在了data中。不过你给的东西在matlab其他地方也很有用,就把分给你吧,谢谢了……

相似回答