Code covered by the BSD License  

Highlights from
Optimizing breakpoints for Tables

image thumbnail

Optimizing breakpoints for Tables

by

 

MATLAB code to support the "Generating Optimal Tables using MATLAB" webinar.

objFcn(delta,M,Xrange,Yrange,refFitObj,Xr,Yr)
% Copyright 2009 The MathWorks, Inc.

function f = objFcn(delta,M,Xrange,Yrange,refFitObj,Xr,Yr)
%
%   delta  = vector of x/y differences, [diff(X),diff(Y)]
%   Xrange = [xmin xmax]
%   Yrange = [ymin ymax]
%   refFitObj = reference (golden standared) fit object
%   Xr/Yr  =  original table points (refernce)
%% Create grid
[x,y] = delta2xy(delta,M,Xrange,Yrange);

%% Create new fit object
ft = 'linearinterp';
opts = fitoptions( ft );
opts.Weights = zeros(1,0);
opts.Normalize = 'on';
[fitObj, gof] = fit( [x(:), y(:)], refFitObj(x(:),y(:)), ft, opts );
%% Calculate residuals
resid = refFitObj(Xr(:),Yr(:)) - fitObj(Xr(:),Yr(:));
f = norm(resid);

Contact us