[4] | 1 | function 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:
|
---|
| 27 | if 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;
|
---|
| 35 | end;
|
---|
| 36 |
|
---|
| 37 | yfit = evalfit(f, f.x);
|
---|
| 38 | yres = f.y - yfit;
|
---|
| 39 |
|
---|
| 40 | if exist('h','var'),
|
---|
| 41 | figure(h);
|
---|
| 42 | hold on;
|
---|
| 43 | else
|
---|
| 44 | figure;
|
---|
| 45 | end;
|
---|
| 46 |
|
---|
| 47 | hres = plot(f.x, yres, 'o');
|
---|
| 48 | title(['Fit Residuals for ' strrep(f.name,'^','\^')]);
|
---|
| 49 | ylabel([f.yvar ' - ' f.yvar '_{fit}']);
|
---|
| 50 |
|
---|
| 51 | if 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;
|
---|
| 63 | end;
|
---|
| 64 |
|
---|
| 65 | gridc x;
|
---|
| 66 | axisc y;
|
---|
| 67 | hold off;
|
---|
| 68 |
|
---|
| 69 | if nargout==0,
|
---|
| 70 | clear yres;
|
---|
| 71 | end;
|
---|