source: MML/trunk/machine/SOLEIL/common/toolbox/ezyfit/ezyfit/showresidual.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 2.0 KB
Line 
1function yres = showresidual(f,h)
2%SHOWRESIDUAL   Show the residuals of a fit
3%   SHOWRESIDUAL(F) displays the residuals for the fit F in a new figure,
4%   ie: plots the difference between the data and the fit.
5%
6%   SHOWRESIDUAL is also available from the item 'Show Fit Residuals' in
7%   the EzyFit menu (see EFMENU).
8%
9%   If F is not specified, plots the residual for the last fit.
10%
11%   YRES = SHOWRESIDUAL(...) returns the residuals (YRES = YDATA - YFIT).
12%
13%   SHOWRESIDUAL(F, H) plots the residual in the figure H.
14%
15%   See also SHOWFIT, EZFIT, EFMENU.
16
17%   F. Moisy, moisy_at_fast.u-psud.fr
18%   Revision: 1.00,  Date: 2006/02/16
19%   This function is part of the EzyFit Toolbox
20
21% History:
22% 2006/02/16: v1.00, first version.
23
24
25% if no input argument, use the last fit, which is stored
26% in the variable lastfit in the 'base' workspace:
27if nargin==0,
28    if evalin('base','exist(''lastfit'',''var'')')
29        f=evalin('base','lastfit');
30    else
31        errordlg('No existing fit. First fit a curve.',...
32            'Show fit residual','on');
33        return;
34    end;
35end;
36
37yfit = evalfit(f, f.x);
38yres = f.y - yfit;
39
40if exist('h','var'),
41    figure(h);
42    hold on;
43else
44    figure;
45end;
46
47hres = plot(f.x, yres, 'o');
48title(['Fit Residuals for ' strrep(f.name,'^','\^')]);
49ylabel([f.yvar ' - ' f.yvar '_{fit}']);
50
51if isfield(f,'hdata')
52    if ishandle(f.hdata),
53        set(hres, 'Color', get(f.hdata, 'Color'));
54        set(hres, 'LineStyle', get(f.hdata, 'LineStyle'));
55        set(hres, 'LineWidth', get(f.hdata, 'LineWidth'));
56        set(hres, 'Marker', get(f.hdata, 'Marker'));
57        set(hres, 'MarkerSize', get(f.hdata, 'MarkerSize'));
58        p=get(f.hdata); pp=get(p.Parent); ppl=get(pp.XLabel);
59        xlabel(ppl.String); % The Xlabel of the residual plot is given
60        % by the XLabel of the original plot.
61        set(gca, 'XScale', pp.XScale);
62    end;
63end;
64
65gridc x;
66axisc y;
67hold off;
68
69if nargout==0,
70    clear yres;
71end;
Note: See TracBrowser for help on using the repository browser.