我用matlab菜单file中的important data直接导入excel,excel中的汉字和数据都以字符形式存入到textdata中了,这样就不能进行矩阵的各种运算了,请问如何正确导入数据,并且导入后是以数字形式出现。初学matlab,有很多东西都不懂,盼高手指教。
这样和我原来用的方法是一样的,得到的数据还是字符形式,而不是数字,也就是你输入textdata得到的矩阵的元素全部都是字符,不能进行矩阵运算的。每个元素上都有' ',或者告诉我怎么把这些字符型的转化为double型的数据也可以。
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。
本回答被网友采纳其实我发现了一个比较简单的方法,就是把excel中的数据改成数字格式,因为是成绩单,所以原来存储的时候为了保证学号前面的0能够出现,都存储成了文本格式,改过之后,再按照原来的导入就可以了。文本格式导入后是存在了textdata中,而数字格式导入后是存在了data中。不过你给的东西在matlab其他地方也很有用,就把分给你吧,谢谢了……