MATLAB Answers


.csv to .mat

Asked by Andy
on 24 Mar 2011

How do I convert .csv files into .mat files. Specifically to interchange new files into the scrips from Algorithmic Trading with MATLAB - 2010 (the webinar). I want to use other files instead of "Bund1min.mat"

Files and webinar:

(Algorithmic Trading with MATLAB - 2010 by Stuart Kozola 22 Nov 2010 (Updated 06 Dec 2010) Code covered by the BSD License Files from the November 18, 2010 webinar.)



No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 24 Mar 2011

csvread() can be used to load data from csv files. You can then save() the data to a .mat file.


on 25 Mar 2011

I am working with the function:
%%file name is in .mat format

d= load('filename');

%% these next couple lines don't seem to work with my newly created file;

lenData = length(data);

on 25 Mar 2011

Maybe it will help if I say step by step what I am trying to do. I download a intra day stock price history csv file from I can either load it into excel to format(I think I have to do this because their is text and a time col. formatted w/ xx:xx) or can try to load the file directly to matlab. When I try to load it into matlab there are errors. I got the excel file to load in and then save as a .mat file when I format the excel file by not having a time col and removing the text headers.

What I want to do: .csv file to .mat file so it can load through with the for mentioned code.

If anyone needs clarification let me know. Thanks for your help in advance

Walter Roberson
on 25 Mar 2011

After you have done the load(), ask to output fieldnames(d) as perhaps the data is not stored in a field named 'data'.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!