www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@constar/fitConstraint.m
function [con, ok] = fitConstraint(con, opts, X) %FITCONSTRAINT Fit a constraint to data % % [CON, OK] = FITCONSTRAINT(CON, OPTS, X) % % X should be the list of boundary points if boundary points are supported by % the constraint. % % See also CONSTAR, % CONBASE/FITCONSTRAINT, % CONSTAR/FINDSPECIALPOINTS, % CONSTAR/FINDBOUNDARYPOINTS, % CONSTAR/GETCONSTRAINTFITOPTIONS. % Copyright 2001-2007 The MathWorks, Inc. and Ford Global Technologies, Inc. Xc = pFilterFactors( con, X ); nf = size( Xc, 2 ); % Ensure that the model is valid if isempty( con.Model ) con.Model = pDefaultModel( con ); elseif nfactors( con.Model ) ~= nf; om = getFitOpt( con.Model ); con.Model = pDefaultModel( con ); con.Model = setFitOpt( con.Model, om ); end % Set model properties based on the given options kernelOpts = get( opts, 'KernelOpts' ); rbf = get( con.Model, 'rbfpart' ); rbf = set( rbf, 'kernel', getname( kernelOpts ) ); rbf = set( rbf, 'width', get( kernelOpts, 'Width' ) ); rbf = set( rbf, 'cont', str2double( get( kernelOpts, 'Cont' ) ) ); con.Model = set( con.Model, 'rbfpart', rbf ); rbfFitOpts = get( opts, 'RbfOpts' ); con.Model = setFitOpt( con.Model, rbfFitOpts ); con.Transform = get( opts, 'Transform' ); % Code the data for fitting Xc = pCodeData( con, Xc ); % 2. Project onto sphere and find radii [Y, R] = map_to_sphere( Xc ); R = transform_radius( R, con.Transform ); % solve interpolation problem, i.e., find f : f(Y(i,:)) = R(i) [m, ok] = runfit( con.Model, Y, R ); ok = logical(ok); if ok % If we are accepting this new model then we need to ensure that the % "fitalg" has not been incorrectly updated. con.Model = set( m, 'fitalg', 'hybridrbffit' ); % make sure all X are inside the boundary md = max(constraintDistance(con,X)); if md>0 con.Offset = 2*md; end end