Problem using textscan to read strings with space inbetween from CSV file
4 views (last 30 days)
Show older comments
Robbin
on 8 Aug 2014
Commented: Michael Haderlein
on 8 Aug 2014
Hi, I've got a problem when trying to using textscan to load the FX data into matlab. The columns are separated by semicolon, but the problem is that there is a space between the date and time strings in the second column. So far, I can only load the data with the following code after trying various delimiter settings:
fid = fopen('test.csv');
rawData = textscan(fid, '%s %s');
However, the outcome is that, counter mixed with date, time stamp mixed with bid/offer prices. Could any one please help me to write the code, so that the first cell contains counter, second column contains date and time, third column for bid price, and fourth for offer price?
Thanks in advance!
USD/JPY,20120102 00:00:00.307,77.023,7.055
USD/JPY,20120102 00:00:00.493,77.03,77.049
USD/JPY,20120102 00:00:05.003,77.03,77.05
USD/JPY,20120102 00:00:05.005,77.023,77.056
USD/JPY,20120102 00:00:05.006,77.024,77.056
USD/JPY,20120102 00:00:06.008,77.023,77.056
USD/JPY,20120102 00:00:06.239,77.03,77.049
0 Comments
Accepted Answer
Michael Haderlein
on 8 Aug 2014
First, you have 4 columns (not 2), so the format is '%s%s%s%s'. Additionally, you have to set the delimiter (which seems to be comma not semicolon):
rawData=textscan(fid,'%s%s%s%s','delimiter',',');
2 Comments
Michael Haderlein
on 8 Aug 2014
You're welcome, however, I find that %s%s%f%f does make much more sense than all %s as I have posted. Anyway, you're gonna make it ;-)
More Answers (0)
See Also
Categories
Find more on Logical 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!