Data Tips -- Add Row Error

37 次查看(过去 30 天)
autumn
autumn 2019-6-10
I'm plotting several things at once and would like to be able to add a data tip row in order to identify the different lines I have running across the plot. Here's my code (I replaced my variables with 'yes' and 'yeehaw'):
for k = 1:length(objects) % yes, yeehaw, and Name are all structs
index = objects(k);
p = plot3(yes(index).yeehaw(:,1),yes(index).yeehaw(:,2),...
yes(index).yeehaw(:,3));
str = yes(index).Name;
fh = str2func(str);
row = dataTipTextRow('yes or yeehaw',fh);
p.DataTipTemplate.DataTipRows(end+1) = row;
And then there are some modifiers for my plot and stuff before the loop closes. I keep getting the following error:
Error using matlab.graphics.datatip.DataTipTemplate/set.DataTipRows. Value must be a string scalar or a character vector with the name of a data property, such as 'XData', or it must be a vector or a function handle.
What can I do?

回答(2 个)

Scotty Neally
Scotty Neally 2020-6-19
I had similar issues but was able to debug them.
They key is that any text you try to put into the new datatip field (ie row 3) must be a cell array of strings the same size as the other 2 rows (XData and YData) because the textbox displays the contents at whatever index the datatip is at.
Example of my implimentation in App Designer:
row = dataTipTextRow('yes or yeehaw',repmat({'yeehaw'},numel(XData),1)); %Creates a string cell the size of XData
H.Children(1).DataTipTemplate.DataTipRows(end+1) = row; %H.Children(1) is handle to plot line

Jan
Jan 2019-6-10
There is no way to provide the value of the data tips as function handle. I cannot guess, what the purpose of using str2func(str) is.
  2 个评论
autumn
autumn 2019-6-10
I've read both, yes, and nothing seems to work. I've also tried
row = dataTipTextRow('oops',yes.yeehaw);
p.DataTipTemplate.DataTipRows(end+1) = row;
And that doesn't seem to work either.
Jan
Jan 2019-6-11
"Nothing seems to work" is not a useful description. Please care for explaining, what you try and what you get as result. Post the code and the error messages, or explain the difference between the results and yopur expectations. It is not clear, what you want to achieve, because the currently posted code contains the creation of a function handle, although the examples in the documentation contains something completely different.
Start with the examples given in the documentation. Then modify these example stepwise until they match your needs. After each modification check, if the code is still running. If not, you know exactly, which modification does not match the needs.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by