フィルターのクリア

change datatype of x axes

18 ビュー (過去 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 Center および File ExchangeAxes Appearance についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by