www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregmodswitch/InitialValues.m

    function data = InitialValues(mdl,Grid)
%INITIALVALUES initial values for multimodels
%
% data = InitialValues(mdl)
% data = InitialValues(mdl,Grid)
% This provides initial values using the model input ranges. The Automatic
% input ranges option should be used as a suitable starting value.

%  Copyright 2007 The MathWorks, Inc. and Ford Global Technologies, Inc.
[LB,UB] = modelranges( mdl );
data = [(LB+UB)'/2 mdl.OpPoints];
if nargin>1
    ng = size(mdl.OpPoints,2);
    if ng>1
        [GridVals{1:ng}] =  ndgrid(Grid{:});
    else
        GridVals = Grid{1};
    end
    X = zeros(numel(GridVals{1}),ng);
    for i=1:ng
        X(:,i) = GridVals{i}(:);
    end
    % reorder points
    [OK,loc] = ismember(X,mdl.OpPoints,'rows');
    data = data(loc(OK),:);
end