change datatype of x axes

16 views (last 30 days)
Sebastian Körner
Sebastian Körner on 15 Oct 2019
Answered: Ranzige Erdnuss on 5 Aug 2020
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?

Accepted Answer

dpb
dpb on 15 Oct 2019
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 Comments
Sebastian Körner
Sebastian Körner on 16 Oct 2019
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 on 16 Oct 2019
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.

Sign in to comment.

More Answers (1)

Ranzige Erdnuss
Ranzige Erdnuss on 5 Aug 2020
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')

Categories

Find more on Axes Appearance in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!