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

13 Ansichten (letzte 30 Tage)
Samuel Weise
Samuel Weise am 27 Jan. 2022
Beantwortet: Zachery Harris am 30 Mai 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?

Antworten (1)

Zachery Harris
Zachery Harris am 30 Mai 2022
For the case where your data is a "vector" of length 1, I was able to solve a similar issue by using a function which just returns the value I wanted. That is, instead of:
row = dataTipTextRow(column_name{:}, v_source);
Try using:
row = dataTipTextRow(column_name{:},@(x) v_source);
in cases where there is only one data point.

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by