Custom Datatip with Line Information on Matrix Plot

I have two matrices. One matrix is plotted and the other has information about each plot line.
Super simplified example:
t = 0:.001:1;
f = [10,20,30]; % information vector
y = sin(2*pi*f.*t'); % output matrix
plot(t,y)
I would like to use the datatip to show the 'f' information along with the x,y coordinates. I am trying to follow the 'myupdatefcn' method using 'datacursormode', but I can't figure out which line (or column of the matrix) I am placing a datatip on.
Any help would be appreciated.

 採用された回答

Adam Danz
Adam Danz 2020 年 10 月 7 日
編集済み: Adam Danz 2020 年 10 月 7 日

1 投票

Loop through the object handles and add the DataTipRows for each object.
t = 0:.001:1;
f = [10,20,30]; % information vector
y = sin(2*pi*f.*t'); % output matrix
h = plot(t,y); % <--- store handle
for i = 1:numel(h)
% Add a new row to DataTip showing f-values
h(i).DataTipTemplate.DataTipRows(end+1) = dataTipTextRow('F',repmat({num2str(f(i))},size(h(i).XData)));
end

2 件のコメント

Kyle Young
Kyle Young 2020 年 10 月 7 日
Thank you!!
That worked like a charm.
Adam Danz
Adam Danz 2020 年 10 月 7 日
Glad I could help.

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

その他の回答 (0 件)

カテゴリ

製品

リリース

R2019a

質問済み:

2020 年 10 月 7 日

コメント済み:

2020 年 10 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by