フィルターのクリア

GCA CurrentPoint with the DateTime Ticks on the X Axis

9 ビュー (過去 30 日間)
abhay  kaul
abhay kaul 2017 年 11 月 29 日
コメント済み: Adam Danz 2020 年 11 月 19 日
I am making a plot where the data is plotted vs Time (HH:MM:SS, for example). I want to be able to click on the plot and display the value of Y. I don't want to use the Data Cursor. I have in the past used the CurrentPoint property of the axes.
This usually returns the actual X and Y values from a mouse click but with the datetime ticks it does not return the actual X. I have tried searching the documentation but I am failing to find what it is outputting. I would like current point to output the value of X in datetime format.
Any ideas?
Thanks
Abhay

採用された回答

Benjamin Kraus
Benjamin Kraus 2018 年 4 月 19 日

Because the CurrentPoint property stores x, y, and z all together in a single matrix, the CurrentPoint cannot reflect the mixed datetime, duration, and numeric data that may be present in the plot. Therefore, CurrentPoint always stores the numeric equivalent.

As Sebastian pointed out, you need to convert from numeric to datetime, but there is actually an easier (and documented) way to do this conversion: num2ruler (and the corresponding ruler2num).

ax(1) = subplot(121); 
DT = datetime(2001:2010, 1:10,1);
plot(DT, rand(length(DT),1)); grid on
ax(2) = subplot(122); grid on
DT = datetime(2018,2,3,4,5,12:.2:15);
plot(DT, rand(length(DT),1)); grid on
set(ax(1),'ButtonDownFcn',@(hax,e) disp(num2ruler(hax.CurrentPoint(1),hax.XAxis)))
set(ax(2),'ButtonDownFcn',@(hax,e) disp(num2ruler(hax.CurrentPoint(1),hax.XAxis)))
  2 件のコメント
abhay  kaul
abhay kaul 2018 年 4 月 19 日
Thanks! Sebastian’s and your answers were very informative. Num2ruler function is what I needed.
Adam Danz
Adam Danz 2020 年 11 月 19 日
What a great find!

サインインしてコメントする。

その他の回答 (1 件)

Sebastian Hölz
Sebastian Hölz 2018 年 2 月 28 日
Hi,
all data is plotted with respect to a reference date, which is stored as property of the axis.
To get the true datetime value, you will need to add this reference-value, e.g.:
figure
ax(1) = subplot(121);
DT = datetime(2001:2010, 1:10,1);
plot(DT, rand(length(DT),1)); grid on
ax(2) = subplot(122); grid on
DT = datetime(2018,2,3,4,5,12:.2:15);
plot(DT, rand(length(DT),1)); grid on
set(ax(1), 'ButtonDownFcn',@(hax,e)disp(hax.XAxis.ReferenceDate + hax.CurrentPoint(1)))
set(ax(2), 'ButtonDownFcn',@(hax,e)disp(second(hax.XAxis.ReferenceDate + hax.CurrentPoint(1))))
Cheers
Sebastian

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by