splinetool.m

来自「演示matlab曲线拟和与插直的基本方法」· M 代码 · 共 1,585 行 · 第 1/5 页

M
1,585 行
字号
	  xname = 'temperature'; yname = 'titanium property';
	  startmethod = 4; % start this one off with spline interpolation
	  hand.messh = ...
	  {{'Spline Interpolation (rather than Cubic Spline Interpolation)';...
	    'on these data does not do a very good job.';...
	    'Try moving the third and the last interior knots a little bit';...
	    'to straighten out the interpolant. (To see the Cubic Spline  ';...
	    'Interpolant for comparison, click on New.)'}, ...
            messtitle, 'non-modal'};

       otherwise
          [x,y] = titanium; xname = 'temperature'; yname = 'titanium property';
          hand.messh = ...
	  {{'Because of the sharp peak, this data set has become a';...
	    'standard challenge to those who would want a satisfactory';...
         'least squares approximation for it with just 5 interior knots.'}, ...
            messtitle, 'non-modal'};
       end %switch menu'Choose some data to work on with the';
    catch
       cf = findobj(allchild(0),'name','Spline Tool');
       if ~isempty(cf)
          errordlg({['Something went wrong during input, as indicated', ...
	            ' by the following error message:'];lasterr},errortit)
          splinetool 'closefile'
       end
       return
    end %try

    if ~exist('x','var')
       errordlg('Data sites are not defined.',errortit), return, end
    if ~exist('y','var')
       errordlg('Data values are not defined.',errortit), return, end
    if length(x)~=length(y)
      errordlg('Sites and values must be vectors of the same length',errortit)
       return
    end

    if isf<0 % the user hit Cancel (in case 1), so we try again
       set(cf,'Userdata',{cf,handles},'Pointer','arrow')
    else % if nothing went wrong, remove the menu and go to finish
       delete(handles), drawnow
       hand.xynames = {x,xname,y,yname,isf, startmethod};
       splinetool('startfinish',hand)
    end

case 'startfinish' % finish the rest of the gui figure:

   hand = y; 
   [x,xname,y,yname,isf,startmethod] = deal(hand.xynames{:});
   hand = rmfield(hand,'xynames');

   backgrey = repmat(0.752941176470588,1,3);
   breakcolor =  backgrey*.8; % would have liked just backgrey
   currentcolor = [0 0 1];
   highcolor =  [1 1 1];
   framecolor = get(hand.figure,'Color');
   units = 'normalized';

    %  make up your own menubar items:
    h1 = uimenu(hand.figure,'Label','&File','Tag','file');
    h2 = uimenu(h1,'Label','&Restart', ...
         'Callback','splinetool ''restart''', ...
         'Tag','restart');
    h2 = uimenu(h1,'Label','&Import Data ...', ...
         'Callback','splinetool ''restart''', ...
         'Separator','on',...
         'Tag','import_data');
    h2 = uimenu(h1,'Label','Export &Data ...', ...
         'Callback','splinetool ''export_data''', ...
         'Separator','on',...
         'Tag','export_data');
    h2 = uimenu(h1,'Label','Export &Spline ...', ...
         'Callback','splinetool ''export_spline''', ...
         'Tag','export_spline');
    h2 = uimenu(h1,'Label','Generate &M-file ...', ...
         'Callback','splinetool ''save2mfile''', ...
         'Tag','save2mfile');
    h2 = uimenu(h1,'Label','&Print to Figure', ...
         'Callback','splinetool ''print_graph''', ...
         'Separator','on',...
         'Tag','print_graph');
    h2 = uimenu(h1,'Label','&Close', 'Callback', 'splinetool ''finish''', ...
         'Separator','on',...
         'Tag','exit');
    h1 =  uimenu(hand.figure,'Label','&Edit',...
         'Tag','editmenu');
    hand.editmenu = h1;
    hand.undo = uimenu(h1,'Label','&Undo','Userdata',[], 'Enable','off' ,...
                   'Callback','splinetool ''undo''','Tag','undo');
    hand.add_item = uimenu(h1,'Label','&Add', ...
         'Callback', 'splinetool ''add_item''', ...
         'Tag','add_item');
    hand.rep_knot = uimenu(h1,'Label','&Replicate Knot', ...
                   'Callback','splinetool ''rep_knot''','Tag','rep_knot');
    hand.del_item = uimenu(h1,'Label','&Delete', ...
         'Callback','splinetool ''del_item''',...
         'Tag','del_item');
    hlab = uimenu(h1,'Label','&Labels ...', 'Callback', ...
                     'splinetool ''labels''', 'Tag','labels');
    viewud = [0 0 0];
    h1 = uimenu(hand.figure,'Label','&View','Userdata',viewud, ...
                   'Tag','viewmenu');
    hand.view(1) = uimenu(h1,'Label','Show &1st Derivative', ...
                                    'Callback','splinetool ''view''', ...
                    'Tag','1view');
    hand.view(2) = uimenu(h1,'Label','Show &2nd Derivative', ...
                                    'Callback','splinetool ''view''', ...
                    'Tag','2view');
    hand.view(3) = uimenu(h1,'Label','Show &Error', ...
                                    'Callback','splinetool ''view''', ...
                    'Tag','3view');
    hand.viewmenu = h1;
    h1 = uimenu(hand.figure,'Label','&Tools', 'Tag','toolmenu');
    hand.tool(1) = uimenu(h1,'Label','Show &Grid', ...
                                    'Callback','splinetool ''tool''', ...
                    'Tag','1tool');
    hand.tool(2) = uimenu(h1,'Label','Show &Legend', ...
                                    'Callback','splinetool ''tool''', ...
		    'Checked','on', 'Tag','2tool');
    hand.toolmenu = h1;
    h1 = uimenu(hand.figure,'Label','&Help');
    h2 = uimenu(h1,'Label','Splinetool &Help', ...
                           'Callback','doc splines/splinetool');
    h2 = uimenu(h1,'Label','Quick &Overview',...
                             'Callback','splinetool(''help'',''about the GUI'')');
    h2 = uimenu(h1,'Label','&Explanation of Terms','Tag','help');
    h3 = uimenu(h2,'Label','&B-spline',...
                                'Callback','splinetool(''help'',''B-spline'')');
    h3 = uimenu(h2,'Label','B&asic Interval',...
                           'Callback','splinetool(''help'',''basic interval'')');
   h3 = uimenu(h2,'Label','B&reaks','Callback','splinetool(''help'',''breaks'')');
    h3 = uimenu(h2,'Label','&Error', 'Callback', ...
                         'splinetool(''help'',''error'')');
     h3 =  uimenu(h2,'Label','&Forms');
     h4 = uimenu(h3,'Label','&B-form', ...
                                    'Callback','splinetool(''help'',''B-form'')');
     h4 = uimenu(h3,'Label','&ppform', ...
                                    'Callback','splinetool(''help'',''ppform'')');
    h3 =  uimenu(h2,'Label','&Interpolation');
     h4 = uimenu(h3,'Label','&Cubic Spline Interpolation', ...
               'Callback','splinetool(''help'',''cubic spline interpolation'')');
     h4 = uimenu(h3,'Label','&End Conditions');
      uimenu(h4,'Label','&remark', ...
                             'Callback','splinetool(''help'',''endconditions'')')
      uimenu(h4,'Label','&not-a-knot', ...
                                'Callback','splinetool(''help'',''not-a-knot'')')
      uimenu(h4,'Label','&clamped or complete', ...
                                    'Callback','splinetool(''help'',''clamped'')')
      uimenu(h4,'Label','&second', ...
                                    'Callback','splinetool(''help'',''second'')')
      uimenu(h4,'Label','&periodic', ...
                                   'Callback','splinetool(''help'',''periodic'')')
      uimenu(h4,'Label','&variational or ''natural''', ...
                               'Callback','splinetool(''help'',''variational'')')
      uimenu(h4,'Label','&Lagrange', ...
                                   'Callback','splinetool(''help'',''Lagrange'')')
      uimenu(h4,'Label','''C&ustomized''', ...
                                 'Callback','splinetool(''help'',''Customized'')')
     h4 = uimenu(h3,'Label','&Spline Interpolation', ...
               'Callback','splinetool(''help'',''spline interpolation'')');

    h3 = uimenu(h2,'Label','&Knots');
     uimenu(h3,'Label','&End Knots', ...
                                'Callback','splinetool(''help'',''end knots'')')
     uimenu(h3,'Label','&Interior Knots',...
                           'Callback','splinetool(''help'',''interior knots'')')
    h4 = uimenu(h3,'Label','&Knots','Callback','splinetool(''help'',''knots'')');
    h3 = uimenu(h2,'Label','&Least-Squares', ...
                           'Callback','splinetool(''help'',''least squares'')');

      uimenu(h2,'Label','&Order', 'Callback','splinetool(''help'',''order'')')
    h3 = uimenu(h2,'Label','&Schoenberg-Whitney Conditions', ...
         'Callback','splinetool(''help'',''Schoenberg-Whitney conditions'')');

    h3 = uimenu(h2,'Label','Sites and &Values', ....
                        'Callback','splinetool(''help'',''sites_etc'')');
    h3 =  uimenu(h2,'Label','S&moothing');
      uimenu(h3,'Label','&Cubic Smoothing Spline', 'Callback', ...
                             'splinetool(''help'',''cubic smoothing spline'')')
      uimenu(h3,'Label','&Quintic Smoothing Spline', 'Callback', ...
                            'splinetool(''help'',''quintic smoothing spline'')')
      uimenu(h3,'Label','&Error Measure', 'Callback', ...
                         'splinetool(''help'',''error'')')
      uimenu(h3,'Label','&Roughness Measure', 'Callback', ...
                         'splinetool(''help'',''roughness measure'')')
      uimenu(h3,'Label','&Weight in Roughness Measure', 'Callback', ...
                         'splinetool(''help'',''weight in roughness measure'')')
   h3 = uimenu(h2,'Label','S&pline','Callback','splinetool(''help'',''spline'')');
    h2 = uimenu(h1,'Label','&Spline Toolbox Commands', ...
                           'Separator','on', ...
                           'Callback','doc splines/refer1_2');
    h2 = uimenu(h1,'Label','&Demos', ...
                           'Callback','demo toolbox spline');
    h2 = uimenu(h1,'Label','&About',...
                           'Separator','on', ...
                           'Callback','splinetool(''help'',''about'')');

   % also provide a context menu, to be active in data mode, and to provide
   % the same capability as the edit commands
   hand.context = uicontextmenu('Parent',hand.figure, ...
              'Position',[.35 .46], ...
              'Tag','context');
     hand.add_item(2) = copyobj(hand.add_item, hand.context);
     hand.rep_knot(2) = copyobj(hand.rep_knot, hand.context);
     hand.del_item(2) = copyobj(hand.del_item, hand.context);


   mat2 = [       0         0    1.0000
                  0    0.5000         0
             1.0000         0         0
                  0    0.7500    0.7500
             0.7500         0    0.7500
             0.7500    0.7500         0
             0.2500    0.2500    0.2500];
   xaxes = .35; dxaxes = .63;

   %%%%%%%%%%%%%%%%%%%%% the axes on which to draw derivatives and such
   hand.Axes(2) = axes('Parent',hand.figure, ...
   	'CameraUpVector',[0 1 0], ...
   	'CameraUpVectorMode','manual', ...
   	'Color',highcolor, ...
   	'ColorOrder', mat2, ...
   	'Position',[xaxes .11 dxaxes .316], ...
        'Visible','off', ...
   	'Tag','Axes2', ...
        'Fontsize',8, ...
	'Box','on', ...
        'ButtonDownFcn','splinetool ''axesclick''', ...
   	'XColor',[0 0 0], ...
   	'YColor',[0 0 0], ...
   	'ZColor',[0 0 0]);
	 xlabel(xname), ylabel('')

   hand.zeroline = line('Xdata',[NaN NaN],'Ydata',[0 0], ...
        'Linewidth',1.5, ...
        'Color',breakcolor, ...
        'Visible','off', ...
        'Tag','zeroline');
   hand.viewline = line('Xdata',NaN,'Ydata',NaN, ...
        'Color',currentcolor, ...
        'Linewidth',2, ...
        'erasemode','normal', ...
        'Tag','viewline');
    % put break/knot lines (also) on second graphic
   hand.breaks(2) = line('Xdata',NaN, 'Ydata',NaN,...
              'Linewidth',1.5, ...
              'erasemode','normal', ...
              'Color',breakcolor, ...
              'visible','off', ...
              'Userdata','off', ...
              'ButtonDownFcn', 'splinetool ''axesclick''', ...
              'Tag','breaks');

   %%%%%%%%%%%%%%%%%%%%% axes on which to draw data and approximations
   hand.Axes(1) = axes('Parent',hand.figure, ...
   	'CameraUpVector',[0 1 0], ...
        'CameraUpVectorMode','manual', ...
   	'Color',highcolor, ...
   	'ColorOrder', mat2, ...
        'Units', units, ...
   	'Position',[xaxes 0.47 dxaxes 0.497], ...
   	'Tag','Axes1', ...
        'Fontsize',8, ...
	'Box','on', ...
        'ButtonDownFcn','splinetool ''axesclick''', ...
        'UIContextMenu',hand.context, ...
   	'XColor',[0 0 0], ...
   	'YColor',[0 0 0], ...
   	'ZColor',[0 0 0]);
         xlabel(xname), ylabel(yname)

   %%%%%%%%%%%%%%%%%%  set up bottom line for showing toolbox commands used:
   hand.bottomlinetext = uicontrol('Parent',hand.figure, ...
   	'BackgroundColor',highcolor, ...
   	'ListboxTop',0, ...
   	'Units',units, ...
   	'Position',[.124 .003 .876 .046], ...
   	'Style','text', ...
        'HorizontalAlignment','left', ...
        'TooltipString', 'Shows toolbox command used', ...
   	'Tag','bottomlinetext');

   uicontrol('Parent',hand.figure, ...
      'BackgroundColor',framecolor, ...
      'ListboxTop',0, ...
      'Units',units, ...
      'Position',[.014 .023 .10 .026], ...
      'String',' Bottomline:', ...
      'Style','text')

   %  %%%%%%%%%%%%%%%%%%%%%%%%%%%  the spline/name manager
        mmpos = [.015 .77-.007, .101, .18]; marg = .008;
   hand.listframe = uicontrol('Parent',hand.figure, ...
        'BackgroundColor',framecolor, ...
        'Units',units, ...
        'Position',[mmpos(1:2)-marg,.25+2*marg,mmpos(4)+3.5*marg], ...
        'Style','frame', ...
        'Tag','nameframe');
   uicontrol('Parent',hand.figure, ...
        'BackgroundColor',framecolor, ...
         'Units',units, ...
         'Position',[mmpos(1)+.005, mmpos(2)+mmpos(4),.19, 4*marg], ...
         'HorizontalAlignment','left', ...
         'String','List of approximations', ...
         'Style','text')

   sl = .032; rw = .15;
   lnpx = rw-sl; lnpy = mmpos(2); ww = lnpx-mmpos(1);
        wh = .045; ph = 3*wh;
   hand.ask_show = uicontrol('Parent',hand.figure, ...
   	'ListboxTop',0, ...
   	'Units',units, ...
   	'Position',[lnpx+.002 lnpy rw wh], ...
   	'Style','checkbox', ...
        'String','Shown in graph', ...
        'Callback', 'splinetool ''toggle_show''', ...
        'TooltipString', 'Show current s

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?