How to display TeX strings in digitized data? (MATLAB hg2)

I recently tried to run an old piece of code (written in hg1) in a new version of MATLAB (2015a) with hg2.

Previously, I could do the following (according to the gnovice - Amro method ):

function output_txt = customDatatip(~,event_obj)
% Display the position of the data cursor
% obj          Currently not used (empty)
% event_obj    Handle to event object
% output_txt   Data cursor text string (string or cell array of strings).

hFig = ancestor(event_obj.Target,'figure'); %// I don't trust gcf ;)

pos = get(event_obj,'Position');
output_txt = {['\lambda: ',num2str(pos(1)*1000,4) 'nm'],...
              ['T(\lambda): ',num2str(pos(2),4) '%']};

set(findall(hFig, 'Type','text', 'Tag','DataTipMarker'),...
      'Interpreter','tex');     %// Change the interpreter

And we get beautifully formatted data labels with Greek characters.

However, on the new system, hg2 findallreturns a 0x0 empty GraphicsPlaceholder array, which makes the installation Interpreteruseless.

My question is: How to install a data interpreter in (La) TeX format in hg2?

+1
source share
1 answer

uiinspect , "TextBox" matlab.graphics.shape.internal.GraphicsTip obj TipHandle, , , Interpreter! public . :

function output_txt = customDatatip(obj,event_obj)
% Display the position of the data cursor // <- Autogenerated comment
% obj          Currently not used (empty) // <- Autogenerated comment, NO LONGER TRUE!
% event_obj    Handle to event object     // <- Autogenerated comment
% output_txt   Data cursor text string (string or cell array of strings). // <- A.g.c.

hFig = ancestor(event_obj.Target,'figure');

pos = get(event_obj,'Position');
output_txt = {['\lambda: ',num2str(pos(1)*1000,4) 'nm'],...
              ['T(\lambda): ',num2str(pos(2),4) '%']};

if ishg2(hFig)
    obj.TipHandle.Interpreter = 'tex';
else %// The old version, to maintain backward compatibility:
        set(findall(hFig, 'Type','text', 'Tag','DataTipMarker'),...
            'Interpreter','tex');     % Change the interpreter
end

function tf = ishg2(fig)
try
    tf = ~graphicsversion(fig, 'handlegraphics');
catch
    tf = false;
end

:

Edit1:

, MATLAB (.. hg1/hg2), , :

function bool = isGraphicsVersion2
%//isGraphicsVersion2 True for Graphic version 2. 

%//   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 21-Jun-2013.
%//   Last Revision: 04-Jul-2013.
%//   Copyright 1995-2013 The MathWorks, Inc.
%//   $Revision: 1.1.6.1 $  $Date: 2013/08/23 23:45:07 $

try
    bool = ~matlab.graphics.internal.isGraphicsVersion1;
catch
    bool = ~isprop(0,'HideUndocumented');
end
0

All Articles