Hi David
The DataTipTemplate functionality is only able to modify that datatip display. It cannot modify the internal data, which is Target, Position and DataIndex. I am assuming you have some code similar to:
% Create a plot with custom data tips
x = 1:10;
y = rand(1,10);
p = plot(x, y);
% DataTipTemplate Method
dtt = p.DataTipTemplate;
dtt.DataTipRows(3).Label = 'Product';
dtt.DataTipRows(3).Value = @(x,y)x*y;
We can create a workaround by writing a custom function:
function data = getCursor(dcm)
data = getCursorInfo(dcm);
for i=1:numel(data)
data(i).Product = data(i).Position(1) .* data(i).Position(2);
end
end
Also you can use data cursor to modify the datatips text
% DataCursor Update Method
dcm = datacursormode(gcf);
set(dcm,'UpdateFcn',@customTip);
function txt = customTip(obj,event_obj)
pos = get(event_obj,'Position');
txt = {...
['X: ', num2str(pos(1))], ...
['Y: ', num2str(pos(2))], ...
['Product: ', num2str(pos(1)*pos(2))] ...
};
end
In any case, we will need to write our custom function to get customdata from the datatips.