Scatter Plot from 1-Row Table needs a String Data Tip Row...

26 views (last 30 days)
Samuel Weise
Samuel Weise on 27 Jan 2022
Edited: Samuel Weise on 27 Jan 2022
I am attempting to add Data Tip Rows to existing scatter plots. In theory, this shouldn't be too bad to do. The value source for these Data Tip Rows are located in the same table used to create the Scatter plots.
function add_datatips(~, sctr, varargin)
for column_name = varargin
v_source = strcat("SourceTable.",column_name{:});
row = dataTipTextRow(column_name{:}, v_source);
sctr.DataTipTemplate.DataTipRows(end+1) = row;
end
end
However, I am receiving the following error when assigning to the DataTipTemplate:
%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 function handle.
In addition to this, I can pull the data column from the Source Table (or even provide a copy of it as another argument to my function), and try using a vector as the value source to dataTipTextRow.
function add_datatips(~, sctr, tblcopy, varargin)
for column_name = varargin
v_source = string(tblcopy(column_name{:}));
row = dataTipTextRow(column_name{:}, v_source);
sctr.DataTipTemplate.DataTipRows(end+1) = row;
end
end
This functions okay until I'm working with a scatter object with only one data point, which is a distinct possibility in my scenario. It seems to read the contents of the height-1 table column as a String Scalar, which is interpreted by dataTipTextRow() as a data property of sctr (one which doesn't exist). This returns the same error as seen above.
Long story short, how can I add DataTipRows for a scatter plot of only one data point if a string vector of length 1 is always interpreted as a String Scalar?

Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by