I am fairly new to Matlab and therefore have some problems related of importing data.
Hey all,
I want to import GDP data and then plot it to time. I was able to import it and translate to string dates. Now I would like to convert it back to my target Matrix. However, I just see values 48 or 49 in my target matrix.
My code is as follows:
AUSGDP = zeros(228,2);
GDP = xlsread('AUDGDP.xlsx');
GDP = GDP(1:228,1) + 693960;
datestring = datestr(GDP,'mm/yyyy');
AUSGDP(228,1) = datestring(228,1)
Thx in advance,
Chris

답변 (2개)

Walter Roberson
Walter Roberson 2016년 9월 10일

0 개 추천

AUSGDP = zeros(228,2);
declares that AUSGDP is to be an array of double precision numbers.
datestring = datestr(GDP,'mm/yyyy');
converts the serial date numbers stored in GDP into strings; in particular into an array of characters.
AUSGDP(228,1) = datestring(228,1)
extracts one of those characters and stores it into one of the floating point numbers. The characters in the first column of datestr('mm') are going to be two digit month numbers, so the first of those characters is going to be either '0' (for months up to September) or '1' (for October to December.) The character '0' has numeric value 48 and the character '1' has numeric value 49; that is char(48) == '0' is true. And 48 and 49 are what are showing up in your output, so your code is doing what you asked it to do.
Peter Perkins
Peter Perkins 2016년 9월 13일

0 개 추천

If you're using R2014b or newer, suggest you look into using datetime, which has explicit conversions to and from excel serial dates. Ideally, you won't need to convert back, because datetimes are much easier to use that the output of datestr, including in plotting.
Hope this helps.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2016년 9월 10일

답변:

2016년 9월 13일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by