How do I convert a CSV formatted string to a table or timetable?
Show older comments
How do I convert a CSV formatted string to a table or time series table, so it then can be plotted as a candle stick plot? The string is the output result of a http: request and could look something like:
'timestamp,open,high,low,close,volume
2019-01-07 14:45:00,102,102.4,103.23,103.00,1955320
2019-01-07 14:46:00,102.3,102.2,102,6,103.9,267856
'
6 Comments
Stephan
on 7 Jan 2019
Can you attach a .mat file of the output you get?
Jonathan
on 7 Jan 2019
Jan
on 7 Jan 2019
@Jonathan: You can simply create such a file using the save command. This makes it easier to write an answer, because we do not have to guess, how the data look like exactly.
textscan should be able to solve the problem efficiently.
Jonathan
on 7 Jan 2019
@Jonathan: An NDA?! You could post the above mentioned example as MAT file for example. This is not a new information, but the readers do not have to retype it, when they try to create an answer. This is not much work, but it can be avoided.
Here is a Matlab command, which creates the data:
str = ['timestamp,open,high,low,close,volume', char(10), ...
'2019-01-07 14:45:00,102,102.4,103.23,103.00,1955320', char(10), ...
'2019-01-07 14:46:00,102.3,102.2,102,6,103.9,267856', char(10)]
You are welcome :-)
It is confusing, that the 2nd line contains 6 elements, and the 3rd 7. Maybe you mean "102.6" instead of "102,6"?
Accepted Answer
More Answers (0)
Categories
Find more on String Parsing 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!