Retain existing column names when creating a timeseries object
Show older comments
I'm only 2 days into using MatLab so please excuse the basic nature question. Also, please restrict the answer to using just MatLab, no addon packages. (I do have the Signal Processing & DSP packages but I'm not looking to spend more money as this is just an old retired EE playing at home.)
I have some stock price and indicator data saved from TradeStation in a general csv format:
mark@c2RAID6 ~/Builder/MatLab $ cat TLT-ex.csv
"Date","Time","Open","High","Low","Close","Vol","OI","Avg"
07/26/2002,16:00,82.67,82.80,82.42,82.51,316300,0,0.00
07/29/2002,16:00,82.06,82.16,81.32,81.42,8400,0,81.74
07/30/2002,16:00,81.75,81.90,81.52,81.52,6100,0,81.71
07/31/2002,16:00,81.95,82.80,81.90,82.53,29400,0,82.35
08/01/2002,16:00,82.54,83.02,82.54,83.00,25000,0,82.78
mark@c2RAID6 ~/Builder/MatLab $
Columns 1-8 are standard TS order. Column 9 (and higher if they exist) change from file to file.
I would like to convert this data to a timeseries object. (I think but that's debatable based on my limited knowledge of MatLab.) To do the conversion I wrote this code:
tmpData = readtable('~/Builder/MatLab/TLT-ex.csv');
Data = tmpData(:,3:size(tmpData, 2));
DataArray=table2array(Data);
DateCell = table2cell(tmpData(:,1));
TS1 = timeseries(DataArray, DateCell);
This seems to work - TS1 is created as a timeseries object - but there are two problems:
1) I'm not retaining the time column
2) I've lost the column names in the table2array step.
So, 3 questions:
1) How can I use the Time column when creating DateCell?
2) Most important, how do I retain the column names. In my general case there are many extra columns with different names which vary from file to file.
3) Once I get the names properly in the timeseries object (and the 'Data' element) how do I access a single column by name? I.e. - something like:
plot(TS1.Avg)
Thanks, Mark
1 Comment
Mark Knecht
on 3 Dec 2014
Edited: per isakson
on 3 Dec 2014
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!