将数据从Excel加载到Matlab [英] Load data from excel to matlab

查看:89
本文介绍了将数据从Excel加载到Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据从excel下载到matlab.我从雅虎财经下载了数据.我想将它们加载到matlab中,但未成功.就在这里,您有我的代码,并且消息matlab正在发送给我.有人可以帮助我改善我的代码吗?

I'm trying to download data from excel to matlab. I downloaded data from yahoo finance. I want to load them in matlab however it's not successful. Right down here you have my codes and the message matlab is sending to me. Can somebody help me to improve my codes?

加载SP100Duan.csv

load SP100Duan.csv

使用加载错误
ASCII文件C:\ Users \ 11202931 \ Desktop \ SP100Duan.csv
的第18行的列数 必须与前几行相同.

Error using load
Number of columns on line 18 of ASCII file C:\Users\11202931\Desktop\SP100Duan.csv
must be the same as previous lines.

推荐答案

有很多方法可以将数据获取到MATLAB中.一般来说,文本/数字混合会带来MATLAB问题.您可能需要清理excel文件,以便在列中没有应为数字的文本.加载数据的一些可能方法:

There are a TON of ways to get data into MATLAB. Generally speaking, mixed text/numbers gives MATLAB problems. You may want to clean up the excel file so there is no text in columns that should be numbers. Some possible methods to load data:

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

这篇关于将数据从Excel加载到Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆