ntamjo achille
ntamjo achille

Reputation: 871

Load data from excel to 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?

load SP100Duan.csv

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.

Upvotes: 0

Views: 5364

Answers (2)

ASH
ASH

Reputation: 20352

This should be pretty simple . . .

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

Also, please see this link. http://www.mathworks.com/help/matlab/ref/xlsread.html

Upvotes: 0

Matthew Gunn
Matthew Gunn

Reputation: 4529

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. 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

Upvotes: 1

Related Questions