How can I load data from a .csv as a string?
16 次查看(过去 30 天)
显示 更早的评论
I'm trying to import data from a .csv in two columns. The first column has dates in mm/dd/yyyy format, and the second has regular numbers. I'm trying to plot this dataset, with the dates on the x axis and numbers on the y. The problem is, when I try to import the first column, it treats the "/" marks as mathematical operators, so I am unable to use it as a date. I can't find a way to load the data as a string, and especially not how to plot it. This is the code I have so far.
totalData = load('FED-RXI_US_N_B_UK.csv');
dates=totalData(1:length(totalData),1);
rates=totalData(2:length(totalData),2);
dateNumber=datenum(dates,'mm/dd/yyyy')
Thanks in advance!
0 个评论
采纳的回答
Star Strider
2016-10-29
Use the xlsread function with at least two (and at best all three) outputs:
[totalData,str,raw] = xlsread('FED-RXI_US_N_B_UK.csv');
The ‘str’ variable should have your dates as a cell array of strings that you can use as an argument to datenum to convert them to date numbers. From there, you can do anything with them you want. The ‘raw’ variable has everything as a cell array in case you need to take the data in the file apart yourself.
2 个评论
Star Strider
2016-10-29
My pleasure.
Yes. See the datetick function.
If you have R2014b or later, also see datetime, a collection of functions to work with and plot dates and times.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!