简体   繁体   English

将数据从Excel加载到MATLAB

[英]Load data from excel to matlab

I'm trying to download data from excel to matlab. 我正在尝试将数据从excel下载到matlab。 I downloaded data from yahoo finance. 我从雅虎财经下载了数据。 I want to load them in matlab however it's not successful. 我想将它们加载到matlab中,但未成功。 Right down here you have my codes and the message matlab is sending to me. 就在这里,您有我的代码,并且消息matlab正在发送给我。 Can somebody help me to improve my codes? 有人可以帮助我改善我的密码吗?

load SP100Duan.csv 加载SP100Duan.csv

Error using load 使用负载时出错
Number of columns on line 18 of ASCII file C:\\Users\\11202931\\Desktop\\SP100Duan.csv ASCII文件C:\\ Users \\ 11202931 \\ Desktop \\ SP100Duan.csv第18行的列数
must be the same as previous lines. 必须与前几行相同。

There are a TON of ways to get data into MATLAB. 有很多方法可以将数据导入MATLAB。 Generally speaking, mixed text/numbers gives MATLAB problems. 一般来说,文本/数字混合会带来MATLAB问题。 You may want to clean up the excel file so there is no text in columns that should be numbers. 您可能需要清理excel文件,以便在列中没有应为数字的文本。 Some possible methods to load data: 加载数据的一些可能方法:

  1. Use readtable function. 使用readtable函数。 Eg. 例如。 mytable = readtable('mycsvfile.csv') All your data is put a table datatype, which I personally find convenient. mytable = readtable('mycsvfile.csv')所有数据都放在表数据类型中,我个人觉得很方便。
  2. You can read data directly from an excel file using xlsread function. 您可以使用xlsread函数直接从excel文件中读取数据。 From your description, it sounds like your datatype is a .csv file though. 根据您的描述,听起来您的数据类型虽然是.csv文件。
  3. Use csvread function. 使用csvread函数。
  4. You can often copy and paste data in excel directly into a variable in Matlab. 您通常可以将excel中的数据直接复制和粘贴到Matlab中的变量中。 eg. 例如。 (i) type: x = 0 , then (ii) double click on x variable in your workspace, then (iii) copy data from excel and paste into your x variable (iv) execute something like save mydata.mat so you can later load it with load mydata.mat (i)输入: x = 0 ,然后(ii)双击工作区中的x变量,然后(iii)从excel复制数据并将其粘贴到x变量中(iv)执行类似save mydata.mat以便以后使用用load mydata.mat加载它

This should be pretty simple . 这应该很简单。 . .

xlsread('C:\\Apple.xls', 'Sheet1', 'A1:G10') xlsread('C:\\ Apple.xls','Sheet1','A1:G10')

Also, please see this link. 另外,请参阅此链接。 http://www.mathworks.com/help/matlab/ref/xlsread.html http://www.mathworks.com/help/matlab/ref/xlsread.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM