www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/@cgexpr/evaluatematrix.m

    function out = evaluatematrix(obj, pMatrix, dInportValues, func, logicalflag)
%EVALUATEMATRIX Evaluate expression over an n-D matrix of numbers
%
%  Y = EVALUATEMATRIX(OBJ, PMATRIX, DMATRIXDEF, QUANTITY) evaluates the
%  expression over a 2-d matrix of points.  The values of the inport
%  matrices are defined in DMATRIXDEF, which is a cell array with the same
%  number of cells as PMATRIX.  Each cell must contain either a matrix, a
%  vector or a scalar.  Vectors are scalar expanded in the appropriate
%  direction to form a correctly sized evaluation point set.  The return is
%  a matrix of values the same size as the input matrix.
%
%  Y = EVALUATEMATRIX(OBJ, PMATRIX, DMATRIXDEF, QUANTITY, LOGICAL)
%  indicates whether the function evaluation will return logical values
%  (LOGICAL=true).
%
%  All other pointers in the inports list that are not in PMATRIX must not
%  contain vectors unless they are dependent on one of the pointers in
%  PMATRIX.  All of the PMATRIX pointers must be independent of each other.
%
%  See also CGEXPR/EVALUATE, CGEXPR/EVALUATEGRID.

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


if nargin<3
    error(message('mbc:cgexpr:InvalidArgument4'));
end

if length(dInportValues) ~= length(pMatrix)
    error(message('mbc:cgexpr:InvalidArgument5'));
end

if nargin<5
    logicalflag = false;
end

if nargin<4
    func = @i_eval;
end


nVals = length(dInportValues);
nDims = max(cellfun('ndims', dInportValues));
InDims = zeros(nVals, nDims);
for n = 1:nDims
    InDims(:, n) = cellfun('size', dInportValues, n);
end
OutDim = max(InDims, [], 1);

isOK = (InDims==1) | (InDims==repmat(OutDim, nVals, 1));
if any(~isOK(:))
    error(message('mbc:cgexpr:InvalidArgument6'));
end


% Expand out any scalar dimensions in the inputs and convert arrays to vectors
if any(OutDim>1)
    for n = 1:nVals
        if any(InDims(n, :)~=OutDim) && ~all(InDims(n, :)==1)
            % Do scalar expansion here if matrices are involved
            repDims = OutDim;
            repDims(InDims(n, :)~=1) = 1;
            dInportValues{n} = repmat(dInportValues{n}, repDims);
        end
        dInportValues{n} =  dInportValues{n}(:);
    end
end

% Perform one big evaluation
passign(pMatrix, parrayeval(pMatrix, @setvalue, {dInportValues}));
out = evaluate(obj, func, logicalflag);
out = reshape(out, OutDim);