www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgprec/pCreateResolutionDisplay.m

    function AP = pCreateResolutionDisplay(obj, hInfo) %#ok<INUSL>
%PCREATERESOLUTIONDISPLAY Create display layout for precision's resolution effect
%
%  LYT = PCREATERESOLUTIONDISPLAY(OBJ, HINFO) creates and returns a layout
%  that can be used for displaying the difference that will exist between a
%  double value and its resolved value due to the precision implementation.

%   Copyright 2000-2015 The MathWorks, Inc.


hGroup = hInfo.PageGroup;
hParent = hInfo.Parent;
hData = xregGui.RunTimePointer;

AP = mbcgui.widget.AxesPanel('Parent', hParent, ...
    'Border', [30 35 165 15]);
ud.hAxes = AP.AxesHandle;
set(ud.hAxes, ...
    'Box', 'on');
ud.hPerfectLine = line('Parent', ud.hAxes, ...
    'Color', [0 .8 0]);
ud.hResolvedLine = line('Parent', ud.hAxes, ...
    'Color', [0 0 .8]);



legend([ud.hPerfectLine; ud.hResolvedLine], ...
    {'y = x'; 'Resolved values'}, ...
    'Location', 'NorthEastOutside'); 

ud.ObjList = event.listener(hGroup, 'ObjectChanged', @(h,evt) i_update(hInfo, hData));
hData.info = ud;
set(AP, 'UserData', hData);

i_update(hInfo, hData);



function i_update(hInfo, hData)
obj = hInfo.getObject;
ud = hData.info;

R = get(obj, 'PhysRange');
if all(isinf(R))
    if isa(obj, 'cgprecfix')
        % Base R on the hardware range
        Rh = get(obj, 'HWRange');
        rng = abs(diff(Rh));
        R = [Rh(1)-rng/2 Rh(2)+rng/2];
    else
        R = [-1000 1000];
    end
end
R = mbcmakelimits(R, 'tight');

% Use the axis width to determine number of points to evaluate
AxSize = get(ud.hAxes, 'Position');
if AxSize(3)>0
    % evaluate a point for each pixel, but use at least 250.  This lower
    % limit will give us a reasonable resolution if the axes are
    % subsequently resized.
    NP = max(250,AxSize(3));
else
    % If the axes size is nonsensical ( 0 or less) then we are probably
    % being created.  The axes are likely to end up a lot bigger.  In this
    % case we will estimate NP based on figure size
    FigSize = get(ancestor(ud.hAxes, 'figure'), 'Position');
    NP = max(250, FigSize(3)-200);
end
x = linspace(R(1), R(2), NP);
y = resolve(obj, x);

set(ud.hPerfectLine, 'XData', x, 'YData', x);
set(ud.hResolvedLine, 'XData', x, 'YData', y);
set(ud.hAxes, 'XLim', R, 'YLim', mbcmakelimits([x y], 'tight'));