Copy and paste date data
이전 댓글 표시
How do I copy this date table to Matlab and create an array so that I can plot the dates vs. data?
5/1/2016 6/1/2016 7/1/2016 8/1/2016 9/1/2016 10/1/2016 11/1/2016 12/1/2016 1/1/2017 2/1/2017 3/1/2017 4/1/2017
Something so easy seems to be so hard! Ive tried (date being the table of dates above): Date = { date} Date = datenum({date}) Date = datetime({date}) Date = datestr(datenum({date}))
Ive tried everything I could find on Google with ‘no dice’. Help.
답변 (2개)
Star Strider
2016년 5월 22일
I don’t know exactly what the problem is because I don’t have your actual data to work with.
Convert your dates to a cell array (if they aren’t already), then use datenum to convert them to date numbers, and datetick on the plot. (I got creative and rotated the x-tick labels to make them readable. That’s been an option for the last few releases.)
The code:
Dates = {'5/1/2016'
'6/1/2016'
'7/1/2016'
'8/1/2016'
'9/1/2016'
'10/1/2016'
'11/1/2016'
'12/1/2016'
'1/1/2017'
'2/1/2017'
'3/1/2017'
'4/1/2017'};
dnv = datenum(Dates);
y = exp((dnv - dnv(1)) * -0.01); % Create Data
figure(1)
plot(dnv, y)
datetick('x', 'yyyy-mm-dd', 'KeepTicks')
set(gca, 'XTickLabelRotation',30)
grid
댓글 수: 2
Sonny Wilson
2016년 5월 23일
Star Strider
2016년 5월 23일
If you ask for the first two outputs from xlsread, you will find the dates as a cell array in the second output. You will not have to add any quotes, since the dates will be imported as a cell array, just as the one I created here. I added the quotes manually because I had to. You won’t.
This call to xlsread:
[d,s] = xlsread(...);
will have the dates in ‘s’. You should be able to use my code with it without modification.
Walter Roberson
2016년 5월 23일
0 개 추천
Use readtable in r2014b or later with datetime objects.
Otherwise the method depends upon whether you are using Windows or not, as xlsread on Windows can end up converting values that you don't want converted.
카테고리
도움말 센터 및 File Exchange에서 Time Series Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!