How can I load data from a .csv as a string?
12 ビュー (過去 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!