필터 지우기
필터 지우기

Convert to serial using only year and month (no day)

조회 수: 2 (최근 30일)
Dave
Dave 2014년 12월 20일
답변: dpb 2014년 12월 20일
Is there a way to convert from matrix A (5x3) where the first element is year and the second element is month (no day element) to a serial number in matrix B (5x2)?
A=...
[2013 12 0.6;
2013 12 0.8;
2014 1 0.5;
2014 2 0.1;
2014 2 0.7]
Answer should be:
B=...
[serial1 0.6;
serial1 0.8;
serial2 0.5;
serial3 0.1;
serial3 0.7]
Where serial1 is a number for 'Dec-2013' and so on. Thanks

채택된 답변

Guillaume
Guillaume 2014년 12월 20일
A date number (serial) has to have a day (and hour, minutes, seconds, if not given, the default is 0:0:0), so use the first of the month for example:
A = [2013 12 0.6; 2013 12 0.8; 2014 1 0.5; 2014 2 0.1; 2014 2 0.7];
B = [datenum(A(:, 1), A(:, 2), 1) A(:, 3)]

추가 답변 (1개)

dpb
dpb 2014년 12월 20일
Sure, just use an arbitrary day -- '1' would be a logical choice although you could choose any day within the month.
B=[datenum(A(:,1), A(:,2), 1) A(:,3)];

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by