www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptimtablefiller/private/pCheckFillFn.m

    function [ok, msg] = pCheckFillFn(fillfn)
%PCHECKFILLFN Check the supplied fill function
%
%  [OK, MSG] = PCHECKFILLFN(FILLFN) checks the fill function supplied to
%  the table filler. The fill function must conform to either or both of
%  the two APIs defined below.
%
%  2-d table:
%
%  [OK, NEWTABDATA, FILLMASK] = FILLFN(COL, ROW, FILLDATA, COLAXIS,
%  ROWAXIS, CURRTABDATA)
%                                
%  COL: xaxis coordinates of data
%  ROW: yaxis coordinates of data
%  FILLDATA: Data at [ROW, COL]
%  COLAXIS: xaxis breakpoints of table, NX-by-1
%  ROWAXIS: yaxis breakpoints of table, NY-by-1
%  CURRTABDATA: existing table data, NY-by-NX
%
%  [OK, NEWTABDATA, FILLMASK] = FILLFN(ROW, FILLDATA, ROWAXIS,
%  CURRTABDATA)
%
%  1-d table:  
%  ROW: yaxis coordinates of data
%  FILLDATA: Data at ROW
%  ROWAXIS: yaxis breakpoints of table, NY-by-1
%  CURRTABDATA: existing table data, NY-by-1
%

%  Copyright 2005-2007 The MathWorks, Inc. and Ford Global Technologies, Inc.


ok = true(1, 2);

% Try the fill function for an example 1-d case
try
    % Arbitrary data for a 1-d example
    testRow = magic(3);
    testRow = testRow(:);
    testRow = 0.25*pi*(testRow-1);
    testData = sin(testRow);
    % Ensure table contains a few cells that can be matched for direct fill
    % routine
    testTableRow = sort([testRow([1 8 9]);linspace(0, 2*pi, 30)']);
    testTableData = zeros(length(testTableRow), 1);
    
    % Evaluate the fill function
    [okf, tabval, fillmask] = feval(fillfn, testRow, testData, ...
        testTableRow, testTableData);
catch
    ok(1) = false;
end

% Try the fill function for an example 2-d case
try
    % Arbitrary data for a 2-d example
    testCol = [1;2;-2;0;-1];
    testRow = (-2:2)';
    testData = peaks(testCol, testRow);
    testTableCol = linspace(-3, 3, 11);
    testTableRow = (-3:3)';
    testTableData = zeros(length(testTableRow), length(testTableCol));
    
    % Evaluate the fill function
    [okf, tabval, fillmask] = feval(fillfn, testCol, testRow, testData, ...
        testTableCol, testTableRow, testTableData);
catch
    ok(2) = false;
end

if ~any(ok)
    ok = false;
    msg = 'The function does not have the correct form for a table filling function';
else
    ok = true;
    msg = '';
end