change datatype of x axes

조회 수: 15 (최근 30일)
Sebastian Körner
Sebastian Körner 2019년 10월 15일
답변: Ranzige Erdnuss 2020년 8월 5일
Hi, i made a GUI where i can plot some data. I can plot my data over numeric values (runtime of my experiment) or datetime values (date of my experiment).
So i can switch between these two modes: Datetime and Runtime
My Problem: when i plotted my data over Datetime and then switch to runtime and want to plot my data i get the following error:
Error using Sondenvergleich_CA_FA>ButtonPreview_Callback (line 280)
Values plotted against x-axis must be datetime values. To create datetime values, use the DATETIME function.
So it seems like my x-axis expects some datetime values but in runtime mode i give numeric values to my axis.
how can i get my xaxis to show numeric values again?

채택된 답변

dpb
dpb 2019년 10월 15일
Axes are not polymorphic--they require a given data type.
You'll have to create two axes and select which to display depending upon which type of data is to be displayed.
If you need both simultaneously, you'll have to have two x axes on the same figure or use two figures.
Inviolate rule.
The only (crude and not recommended) way around would be to use the venerable datenum instead of datetime class. datenum is just a double camoflauged as a date; to make the axis represent dates one has to use the deprecated and klunky datetick function. As noted, NOT recommending this, but it is a way to put either on the same axis.
  댓글 수: 2
Sebastian Körner
Sebastian Körner 2019년 10월 16일
Thanks for your answer. I made it work with two axes now.
But just for my understanding: why is it possible to use numeric values for my xaxis and the switch to datetime, but the other way round its not possible?
dpb
dpb 2019년 10월 16일
Just the way TMW implemented the datetimeruler object internals -- it doesn't have the ability to switch back to normal double and regular axes object with internal callback routines once it is in place.
Not that they couldn't have done, but I suppose it never came to them that somebody would want to do so...
One can always submit an enhancement request with an example use such as yours as to why it should be possible.

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

추가 답변 (1개)

Ranzige Erdnuss
Ranzige Erdnuss 2020년 8월 5일
for me
cla(app.UIAxes,'reset')
made it possible to plot double values after I plotted some datetime values. After this command you must reset the axis labels again via:
xlabel(app.UIAxes, 'X Label')
ylabel(app.UIAxes, 'Y Label')

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by