How to add additional info to the data cursor?

29 ビュー (過去 30 日間)
Lukas
Lukas 2013 年 3 月 21 日
コメント済み: akhila 2023 年 9 月 20 日
Hello
I'm wondering how I can get extra info (which is not plotted itself) to show on the data cursor of a plot.
Say I have multiple events, and three variables per event (nicely stashed in arrays), e.g. the time of the event, the position and some measured value. Say now that I plot this measured value against the position. Is there some way to also have the time of the event displayed in the data cursor per event?
Thanks in advance.
Lukas
(sorry for the self-bumping)

採用された回答

ChristianW
ChristianW 2013 年 3 月 22 日
編集済み: ChristianW 2013 年 3 月 26 日
function test_main
% Plots graph and sets up a custom data tip update function
fig = figure('DeleteFcn','doc datacursormode');
X = 0:60;
t = (X)*0.02;
Y = sin(-16*t);
plot(X,Y)
dcm_obj = datacursormode(fig);
set(dcm_obj,'UpdateFcn',{@myupdatefcn,t})
function txt = myupdatefcn(~,event_obj,t)
% Customizes text of data tips
pos = get(event_obj,'Position');
I = get(event_obj, 'DataIndex');
txt = {['X: ',num2str(pos(1))],...
['Y: ',num2str(pos(2))],...
['I: ',num2str(I)],...
['T: ',num2str(t(I))]};
  7 件のコメント
Julia Jose
Julia Jose 2020 年 2 月 18 日
lifesaver! Works perfectly, thank you!
akhila
akhila 2023 年 9 月 20 日
what is event object and obj ? is it a data we load?

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

その他の回答 (1 件)

Iann Caio
Iann Caio 2022 年 2 月 10 日
Hello .. Good night. Is there any method, where I click on a certain point in the figure, and I want to extract the data from the cursor, and add it to a new program in PROMPT?

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by