Code covered by the BSD License

# Optimizing breakpoints for Tables

### Richard Willey (view profile)

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

new_visuals.m
```% Copyright 2009 The MathWorks, Inc.

[xvector yvector] = meshgrid(x,y);

xvector = xvector(:);
yvector = yvector(:);

zvector = peaks(xvector, yvector);

foo = fit([xvector, yvector], zvector, 'cubicinterp')
%plot(foo)

%%

Diff = refFitObj(Xr(:), Yr(:)) - foo(Xr(:), Yr(:))

Diff_Contour = fit([Xr(:), Yr(:)], Diff, 'linearinterp');

figure('Numbertitle', 'off', 'name', 'Difference between Surfaces')

xlim = [-3, 3];
ylim = [-3, 3];
obj = Diff_Contour;

% Nicked from sfit/plot
[xi, yi] = meshgrid( ...
linspace( xlim(1), xlim(2), 49 ), ...
linspace( ylim(1), ylim(2), 51 ) );
zi = feval( obj, xi, yi );

[~, h] = contourf( xi, yi, zi, 21 );

grid on
colorbar
caxis ([-1.3 1.3])

hold on
scatter(xvector, yvector, 'k', 'filled')

%%

figure
plot(refFitObj, 'style', 'contour')

%% Equidistant

Diff2 = refFitObj(Xr(:), Yr(:)) - fitObj(Xr(:), Yr(:));

Diff_Contour2 = fit([Xr(:), Yr(:)], Diff2, 'linearinterp');

figure

xlim = [-3, 3];
ylim = [-3, 3];
obj = Diff_Contour2;

% Nicked from sfit/plot
[xi, yi] = meshgrid( ...
linspace( xlim(1), xlim(2), 49 ), ...
linspace( ylim(1), ylim(2), 51 ) );
zi = feval( obj, xi, yi );

[~, h] = contourf( xi, yi, zi, 21 );

grid on
colorbar
caxis ([-1.3 1.3])

hold on
scatter(X(:), Y(:), 'k', 'filled')

%% Performance Charts

hold off

Plot1 = plot(Size, Spline_Opt, 'color', 'b', 'linewidth', 2);

hold on

Plot2 = plot(Size, Spline_Uniform, 'color', 'b', 'linestyle', '--', 'linewidth', 2);
Plot3 = plot(Size, Linear_Opt, 'color', 'k', 'linewidth', 2);
Plot2 = plot(Size, Linear_Uniform, 'color', 'k', 'linestyle', '--', 'linewidth', 2);

%%
a = -3; b = 3;
X = linspace(a,b,13);
Y = linspace(a,b,13);
[X,Y] = meshgrid(X,Y);
XVector = X(:);
YVector = Y(:);
ZMatrix = peaks(XVector,YVector);

```