Data Tips -- Add Row Error

38 visualizaciones (últimos 30 días)
autumn
autumn el 10 de Jun. de 2019
Respondida: Scotty Neally el 19 de Jun. de 2020
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?

Respuestas (2)

Scotty Neally
Scotty Neally el 19 de Jun. de 2020
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 el 10 de Jun. de 2019
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 comentarios
autumn
autumn el 10 de Jun. de 2019
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 el 11 de Jun. de 2019
"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.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by