default_getDatatipText.m MATLAB R2014+

2 Ansichten (letzte 30 Tage)
Paul Boschert
Paul Boschert am 4 Jan. 2016
Kommentiert: Hannes am 13 Mai 2020
I'd like to change the default data tip that's displayed on plots in MATLAB R2014+ versions. Before, one could edit the file default_getDatatipText.m and change the number of digits. Now that file no longer exists.
I'd like to change the default behavior instead of changing the datacursor mode to a custom update function.
e.g. I could do something like this: dcm = datacursormode; set(dcm, 'UpdateFcn', @tenDigitTextUpdate)
But I'd rather change the default instead.

Antworten (1)

Joe Vinciguerra
Joe Vinciguerra am 11 Nov. 2019
(courtesy of stackoverflow)
add the following to your startup.m file:
set(0,'defaultFigureCreateFcn',@(s,e)datacursorextra(s))
Create a new M-file in your matlab path called "datacursorextra.m" and insert the following into that file:
function datacursorextra(fig)
% Use current figure as default
if nargin<1
fig = gcf;
end
% Get the figure's datacursormode, and set the update function
h = datacursormode(fig);
set(h,'UpdateFcn',@myupdatefcn)
% The actual update function
function txt = myupdatefcn(~,event)
% Short-hand to write X, Y and if available Z, with 10 digit precision:
lbl = 'XYZ';
txt = arrayfun(@(s,g)sprintf('%s: %.10g',s,g), lbl(1:length(event.Position)), event.Position,'uniformoutput',false);
% If a DataIndex is available, show that also:
info = getCursorInfo(h);
if isfield(info,'DataIndex')
DataIndex = [info.DataIndex];
txt{end+1} = sprintf('Index: %d\n', DataIndex(1));
end
end
end
Change the formatting in line 15 to your liking.
  1 Kommentar
Hannes
Hannes am 13 Mai 2020
This works well and I have been using the startup.m file to customize default settings.
However, this seems to crash the App Designer! (2019b and 2020a)

Melden Sie sich an, um zu kommentieren.

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by