Home > atdemos > gui > atslider.m

atslider

PURPOSE ^

ATSLIDER is an example of a GUI control of multiple parameters in THERING

SYNOPSIS ^

function fig = atslider(varargin)

DESCRIPTION ^

ATSLIDER is an example of a GUI control of multiple parameters in THERING
 by mapping from one-dimensional control parameter space.
 The value of the control parameter is set
 with a slider or typed in a text window. When it is modified
 each of the controlled variables is modified accordingly

 HANDLE = ATSLIDER(KnobData,KnobName)
     creates a new knob figure identified with KnobName
    with  a slider and editable text. The initial value is set to 0
  
  KnobData is MATLAB structure arrray where each element corresponds to
       one controlled paramater in THERING and controls what gets modified
       in the ring when the slider value changes
         
       Position             Index of an element to be modified in THERING
         FieldName       Name of the field in the element data structure 
                       whos value will bi modified
         M,N             When a field is an array M,N index an element (PolynomA)
                       When a field is a scalar set M=N=1 
         Weight          Mapping coefficient between slider position and controlled value

    HANDLE = ATSLIDER(KnobData,KnobName,COMMAND)
            evaluates COMMAND in MATLAB base workspace
        for example try COMMAND = 'plotbeta'  for dynamically updating betafunctions

 ATSLIDER(action) with proper 'action' stringis is recursively called 
 from inside the ATSLIDER function to evaluate callbacks
        'set'
        'reset'

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fig = atslider(varargin)
0002 %ATSLIDER is an example of a GUI control of multiple parameters in THERING
0003 % by mapping from one-dimensional control parameter space.
0004 % The value of the control parameter is set
0005 % with a slider or typed in a text window. When it is modified
0006 % each of the controlled variables is modified accordingly
0007 %
0008 % HANDLE = ATSLIDER(KnobData,KnobName)
0009 %     creates a new knob figure identified with KnobName
0010 %    with  a slider and editable text. The initial value is set to 0
0011 %
0012 %  KnobData is MATLAB structure arrray where each element corresponds to
0013 %       one controlled paramater in THERING and controls what gets modified
0014 %       in the ring when the slider value changes
0015 %
0016 %       Position             Index of an element to be modified in THERING
0017 %         FieldName       Name of the field in the element data structure
0018 %                       whos value will bi modified
0019 %         M,N             When a field is an array M,N index an element (PolynomA)
0020 %                       When a field is a scalar set M=N=1
0021 %         Weight          Mapping coefficient between slider position and controlled value
0022 %
0023 %    HANDLE = ATSLIDER(KnobData,KnobName,COMMAND)
0024 %            evaluates COMMAND in MATLAB base workspace
0025 %        for example try COMMAND = 'plotbeta'  for dynamically updating betafunctions
0026 %
0027 % ATSLIDER(action) with proper 'action' stringis is recursively called
0028 % from inside the ATSLIDER function to evaluate callbacks
0029 %        'set'
0030 %        'reset'
0031 
0032 global THERING
0033 
0034 if nargin >1 % initial call
0035     
0036  
0037 
0038 KnobData = varargin{1};
0039 KnobName = varargin{2};
0040 
0041 % make a copy of original values of all controlled parametes
0042 NumVar = length(KnobData);
0043 I = [KnobData.Position];
0044 F = [KnobData.FieldName];
0045 M = [KnobData.M];
0046 N = [KnobData.N];
0047 W = [KnobData.Weight];
0048 for i = 1:NumVar
0049    OriginalValues(i) = getfield(THERING{I(i)},F(i),{M(i),N(i)});
0050 end
0051 
0052 
0053 h0 = figure('Color', [0.8 0.8 0.8], ...
0054     'FileName','D:\MATLABR11\work\atslider.m', ...
0055    'HandleVisibility', 'Callback' , ...
0056     'PaperPosition',[18 180 576 432], ...
0057     'PaperUnits','points', ...
0058     'Position',[520 400 300 140], ...
0059     'Tag','Fig1', ...
0060     'ToolBar','none');
0061 if nargout > 0 
0062    fig = h0; 
0063 end
0064 
0065 s1 = uicontrol('Parent',h0, ...
0066     'Units','points', ...
0067     'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ...
0068     'ListboxTop',0, ...
0069     'Position',[20 20 100 15], ...
0070    'Style','slider', ...
0071    'Max',1, 'Min', -1, ...
0072    'Callback','atslider set', ...
0073    'Tag','Slider1');
0074 
0075 e1 = uicontrol('Parent',h0, ...
0076     'Units','points', ...
0077     'BackgroundColor',[1 1 1], ...
0078     'ListboxTop',0, ...
0079     'Position',[140 20 65 15], ...
0080    'Style','edit', ...
0081    'Callback','atslider set', ...
0082    'Tag','EditText1');
0083  
0084 
0085 if nargin == 2 
0086     set(h0,'UserData',{e1 s1 KnobData OriginalValues});
0087 elseif nargin == 3
0088     set(h0,'UserData',{e1 s1 KnobData OriginalValues varargin{3}});
0089 end
0090 
0091 
0092 t1 = uicontrol('Parent',h0, ...
0093     'Units','points', ...
0094     'BackgroundColor',[0.8 0.8 0.8], ...
0095     'FontSize',12, ...
0096     'ListboxTop',0, ...
0097     'Position',[20 60 165 20], ...
0098     'String',KnobName, ...
0099     'Style','text', ...
0100     'Tag',KnobName);
0101 
0102 elseif nargin == 1
0103    action = varargin{1};
0104    
0105 
0106    UD = get(gcbf,'UserData');
0107    eh = UD{1};
0108     sh = UD{2};
0109     OV = UD{4};  
0110     if(length(UD)==5) 
0111         COMMAND = UD{5};
0112         % quick fix
0113         COMMAND = strcat('figure(3);',COMMAND);
0114     else 
0115         COMMAND = '';
0116    end
0117     
0118 
0119    I = [UD{3}.Position];
0120     F = [UD{3}.FieldName];
0121     M = [UD{3}.M];
0122     N = [UD{3}.N];
0123     W = [UD{3}.Weight];
0124 
0125    switch lower(action)
0126    case 'set'
0127       whoiscalling = gcbo;
0128       %synchronize slider and text
0129       switch(whoiscalling)
0130       case sh 
0131          newvalue = get(sh,'Value');
0132          set(eh,'String',newvalue)
0133       case eh
0134          newvalue = sscanf(get(eh,'String'),'%f');
0135          set(sh,'Value',newvalue);
0136       end
0137       
0138       
0139       %update controlled variables in the worksapce
0140       for i = 1:length(OV)
0141          THERING{I(i)}=setfield(THERING{I(i)},F(i),{M(i),N(i)},OV(i)+newvalue*W(i));
0142       end
0143        evalin('base',COMMAND);  
0144    case 'reset'
0145       %Do nothing for now
0146    end
0147    
0148 end
0149 
0150    
0151 
0152

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005