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

    function [m,ok]=gui_localmodopts(m,action,fig,p)
%GUI_LOCALMODOPTS  Local model options dialog
%
%   [M,OK]=GUI_LOCALMODOPTS(M) creates a modal dialog for setting up
%   options specific to the current local model class.  This function is
%   the default, creating a simple 'No options available dialog'.  Overload
%   it in local models which have additional options such as spline order.
%
%   LYT=GUI_LOCALMODOPTS(M,'layout',FIG,P) creates and returns a layout in
%   figure FIG, based around altering the model in the pointer P.  This
%   interface must be supported by overloaded methods.  FIG may also be an
%   existing layout object in which case the layout is updated with fresh
%   information from the model in P.

%  Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc.


if nargin<2
    action='figure';
end

switch lower(action)
    case 'figure'
        [m,ok] = gui_localmodoptsdlg(m);
    case 'layout'
        m=i_createlyt(fig,p);
end


function lyt=i_createlyt(figh,p)

if ~isa(figh,'xregcontainer')
    ud.pointer=p;
    ud.figh=figh;

    ud.knots=xregGui.labelcontrol('parent',figh,...
        'ControlSize',60,...
        'visible','off',...
        'String','Number of knots:',...
        'Control',mbcgui.widget.Spinner('Parent',figh,...
        'Visible','off',....
        'ClickIncrement',1,...
        'Min',1,...
        'Max',1000,...
        'Rule','int'));
    ud.order=xregGui.labelcontrol('parent',figh,...
        'ControlSize',60,...
        'visible','off',...
        'String','Spline order:',...
        'Control',mbcgui.widget.Spinner('Parent',figh,...
        'Visible','off',...
        'ClickIncrement',1,...
        'Min',0,...
        'Max',3,...
        'Rule','int'));

    ud.rand=xregGui.labelcontrol('parent',figh,...
        'ControlSize',60,...
        'visible','off',...
        'String','Random starting points:',...
        'Control',mbcgui.widget.Spinner('Parent',figh,...
        'Visible','off',...
        'ClickIncrement',1,...
        'Min',0,...
        'Max',1000,...
        'Rule','int'));

    % data
    udh=ud.knots;

    % callbacks
    set(ud.knots.Control,'Callback',{@i_knotchng,udh});
    set(ud.order.Control,'Callback',{@i_orderchng,udh});
    set(ud.rand.Control,'Callback',{@i_randchng,udh});

    lyt=xreggridbaglayout(figh,'dimension',[3,1],...
        'packstatus','off',...
        'rowsizes',[20 20 20],...
        'gap',5,...
        'elements',{ud.knots,ud.order,ud.rand});

    set(ud.knots,'UserData',ud);
else
    el = get(figh,'elements');
    ud=get(el{1},'UserData');
    ud.pointer=p;
    set(el{1},'UserData',ud);
    lyt=figh;
end
i_setvalues(ud,p);


function i_setvalues(ud,p)
m=p.info;
nk= get(m,'numknots');
k= get(m,'order');
set(ud.knots.Control,'Value',nk);
set(ud.order.Control,'Value',k);
if ~isfield(m.fitparams,'randstart')
    m.fitparams.randstart= 2;
    p.info= m;
end
set(ud.rand.Control,'Value',m.fitparams.randstart);


function i_knotchng(src,evt,udh)
ud=get(udh,'UserData');
val=get(ud.knots.Control,'Value');
m=ud.pointer.info;
k=get(m,'numknots');
if k~=val
    m=set(m,'numknots',val);
    ud.pointer.info=m;
end


function i_orderchng(src,evt,udh)
ud=get(udh,'UserData');
val=get(ud.order.Control,'Value');
m=ud.pointer.info;
k=get(m,'order');
if k~=val
    m=set(m,'order',val);
    ud.pointer.info=m;
end


function i_randchng(src,evt,udh)
ud=get(udh,'UserData');
val=get(ud.rand.Control,'Value');
m=ud.pointer.info;
m.fitparams.randstart= val;
ud.pointer.info=m;