How can I plot datetime as x-axis in pcolor ?

조회 수: 10 (최근 30일)
Jeevan Kumar Bodaballa
Jeevan Kumar Bodaballa 2019년 10월 14일
댓글: Adam Danz 2019년 10월 15일
Hello Seniors,
I have time(datetime - 6047X1) need to be in x-axis, height(numeric value - 27X1) as y axis, C(27X6047) numeric values.
I am having error(Error using pcolor (line 65) Data inputs must be real.) while I want plot by using pcolor.
  댓글 수: 4
Shubham Gupta
Shubham Gupta 2019년 10월 14일
One of the way can be:
dt = [datetime('yesterday'),datetime('today'),datetime('tomorrow')];
y = 1:3;
C = [3 4 5; 1 2 5; 5 5 5];
pcolor(datenum(dt),1:3,C)
a = gca;
a.XTick = datenum(dt);
a.XTickLabel = datestr(datenum(dt));
I am not sure if that's what you want but let me know if you have doubts.
Jeevan Kumar Bodaballa
Jeevan Kumar Bodaballa 2019년 10월 15일
Thanks a lot it worked.
A small question that is any simple command to see specific dates from whole time.
for example : I have time scale 01/01/2015 to 10/02/2015. And now I want plot only 10/01/2015 to 15/01/2015. (with/without using logical index).

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2019년 10월 14일
편집: Adam Danz 2019년 10월 14일
There must be imaginary data in your inputs. Here's a demo with valid datetime inputs.
dt = [datetime('yesterday'),datetime('today'),datetime('tomorrow')];
y = 1:3;
C = [3 4 5; 1 2 5; 5 5 5];
pcolor(dt,1:3,C)
To determine if imaginary data exist anywhere within a numeric array, use isreal() which will either return a TRUE or FALSE indicating whether all of the data in your array are real numbers. If it returns a false, you can use imag() to find the element that is not real.
Note that pcolor() did not accecpt datetime values prior to r2019b.
In current documentation you can see that datetime is listed as an accepted data type. In r2019a documentation, pcolor does not list datetime as an accepted input. Using datetime as an input to pcolor() in r2019a or earlier will result in the error, "Data inputs must be real."
  댓글 수: 5
Jeevan Kumar Bodaballa
Jeevan Kumar Bodaballa 2019년 10월 15일
Yeah r2019b have direct access to plot datetime in x-axis.
Thanks a lot it worked.
A small question that is any simple command to see specific dates from whole time.
for example : I have time scale 01/01/2015 to 10/02/2015. And now I want plot only 10/01/2015 to 15/01/2015. (with/without using logical index).
Adam Danz
Adam Danz 2019년 10월 15일
Logical indexing would be best. Suppose your date vector is named dt,
idx = dt>=DATE1 & dt <=DATE2;
Then you could set those values to NaN,
x(idx) = NaN;
y(idx) = NaN;
pcolor(x,y,C)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by