Home > marsbar > @mardo > ui_get_contrasts.m

ui_get_contrasts

PURPOSE ^

SPM contrast UI, wrapped for MarsBaR

SYNOPSIS ^

function varargout=ui_get_contrasts(D, varargin)

DESCRIPTION ^

 SPM contrast UI, wrapped for MarsBaR

=======================================================================
 - FORMAT specifications
=======================================================================
( This is a multi function function: If the first argument is a string,)
( then this is the action string, specifying the particular action     )
( function to take.                                                    )

 FORMAT [I,D,changef] = ui_get_contrasts(D,STATmode,n,Prompt,Mcstr,OK2chg)

 Takes design, offers contrast GUI, returns possibly modified design
 Fields used in design are:
   xX         - Design Matrix structure
              - (see spm_spm.m for structure)
              - fields used directly are:
   .xKXs      - space structure of smoothed design matrix
   .name|xNames - cellstr of parameter names

   xCon     - Contrast definitions structure array
                (see spm_FcUtil.m for structure, rules & handling)
              - defaults to empty contrast structure
              - fields used directly are:
   .name      - contrast name string
   .STAT      - character describing statistic required: 'T' or 'F'
   .c         - contrast weights (column) vector / matrix

 STATmode   - string indicating STAT modes to allow contrast 
              selection/definition for:
            - 'T' to limit to (1-dimensional) contrasts defined for SPM{t}
            - 'F' to limit to contrasts defined for SPM{F}
            - 'T|F' to allow either contrasts for SPM{t} or SPM{F}
              (both may be defined, but only one type may be selected)
            - 'T&F' to allow both contrasts for SPM{t} and SPM{F}
            - defaults to 'T|F'

 n          - Number of contrasts to select, Inf for unlimited

 Prompt     - Prompt string

 Mcstr      - string to describe multiple contrast selection
              E.g. ' for conjunction' will result in the status message
                   reading 'Selected 2 contrasts for conjunction' when
                   two contrasts are selected.

 OK2chg     - logical, specifying whether the contrast structure can be
              changed. If false, then new contrasts cannot be defined, and
              existing contrasts cannot be renamed.

 I          - Index (or indices) of contrasts selected

 D (out)    - Design with modified contrast definitions structure array 
 changef    - flag set to 1 if contrast definitions have changed

                           ----------------

 [F,cF] = ui_get_contrasts(D, 'Initialise',...
                              Vis,STATmode,n,Prompt,Mcstr,OK2chg)
 Initialise mConMan GUI for contrast selection/definition
 Vis        - Initialisation action:
              'close' - closes mConMan window
              'off'   - hides mConMan window
              'reset' - hides and resets mConMan window
              'on'    - initialises mConMan window using arguments given
 STATmode   - string indicating STAT modes to allow contrast 
 n          - number of contrasts to select, Inf for unlimited
 Prompt     - Prompt string
 Mcstr      - string to describe multiple contrast selection
 OK2chg     - logical, specifying whether contrast structure can be changed
 F          - figure used for contrast manager window
 cF         - Figure which was current before function call

 FORMAT ui_get_contrasts(D, 'ListCon',hConList,STAT,I)
 Utility function to list contrasts in ListBox
 hConList   - handle of GUI ListBox object
 STAT       - STAT character: 'T' or 'F' or empty (show all)
 I          - indices of currently selected contrasts
 
 FORMAT ui_get_contrasts(D, 'GraphCons',xCon,I,F)
 Utility function to display contrast image/bar-graph & setup "surfing"
 xCon       - contrast definitions structure array
 I          - indicies of contrasts to display
 F          - handle of 'mConMan' figure

 FORMAT ui_get_contrasts(D, 'StatusLine',F,str,col)
 Utility function to update mConMan window statusline
 F          - handle of 'mConMan' figure
 str        - string to display
              (defaults to status of contrast selection)
 col        - colour to use [defaults to 'w' - white

 FORMAT ui_get_contrasts(D, 'Done_CB')
 CallBack for "Done" button on mConMan contrast selection interface

 FORMAT ui_get_contrasts(D, 'ConList_CB')
 CallBack for contrast selection ListBox

 FORMAT STAT = ui_get_contrasts(D, 'TFA')
 CallBack for 'T','F' or 'any' STAT selection RadioButtons
 FORMAT STAT = ui_get_contrasts(D, 'TFA',F,STAT)
 Initialisation of 'T','F' or 'any' STAT selection RadioButtons
 FORMAT STAT = ui_get_contrasts(D, 'TFA',F,STAT,STATmode)
 Function to set STAT & STATmode
 Initialisation of 'T','F' or 'any' STAT selection RadioButtons & STATmode
 F          - handle of 'mConMan' figure
 STAT       - STAT character: 'T' or 'F' of empty (all)
 STATmode   - string indicating STAT modes to allow contrast 

 FORMAT ui_get_contrasts(D, 'FConMenu_CB')
 CallBack to set state of mConMan contrast selection figure context menu

 FORMAT ui_get_contrasts(D, 'Rename_CB')
 CallBack to handle contrast renaming

 FORMAT [c,I,emsg,imsg,msg] = ui_get_contrasts(D, 'ParseCon',cstr,X,STAT)
 Contrast weights parser: Catch evaluation errors and invalid contrasts
 cstr       - string (or cellstr) to evaluate to get contrast(s)
 X          - design matrix
 STAT       - 'T' or 'F' (for contrast checking)
 c          - contrast weights matrix
 I          - logical validity indicator: indicates which rows of 
              cellstr(cstr) generated valid contrasts which were 
              included in c
 emsg       - cellstr of error messages produced during parsing
 imsg       - cellstr of information messages for valid contrasts 
 msg        - cellstr of all messages produced during parsing,
              one cell per string in cstr
 
 FORMAT [iX0,I,emsg,imsg] = ui_get_contrasts(D, 'ParseIStr',str,max)
 DesMtx column index parser: Catch eval errors and invalid indices
 str        - string for evaluation to get column indices
 max        - number of columns in design matrix
 iX0        - vector of column indices: '!' if evaluation error
 I          - 0 if evaluation error, 1 if evaluated OK
 emsg       - error message
              (evaluation errors, non-integer indices, out of range indices)
 imsg       - information message (valid indices)

 FORMAT ui_get_contrasts(D, 'Reset_CB')
 CallBack handler for "reset" button on contrast selection interface

 FORMAT ui_get_contrasts(D, 'D_Setup_CB')
 CallBack handler for "Define new" button:
 Initialises Contrast Definition interface for use

 FORMAT ui_get_contrasts(D, 'D_ConMtx_CB')
 CallBack handler for contrast weights definition widget
 FORMAT ui_get_contrasts(D, 'D_X1cols_CB')
 Callback handler for F-contrast "columns for reduced design" widget

 FORMAT ui_get_contrasts(D, 'D_Reset_CB')
 CallBack handler for "reset" button on contrast definition interface

 FORMAT ui_get_contrasts(D, 'D_Cancel_CB')
 CallBack handler for "cancel" button on contrast definition interface

 FORMAT ui_get_contrasts(D, 'D_OK_CB')
 CallBack handler for "OK" button on contrast definiton interface

 FORMAT ui_get_contrasts(D, 'D_Status',F)
 Set status line of contrast definition interface
 F          - Handle of mConMan figure [defaults gcbf]

 FORMAT [F,H] = ui_get_contrasts(D, 'CreateFig')
 Creates mConMan dialog figure (definition interface initially hidden)
 F          - Handle of mConMan figure created
 H          - Stricture of Handles:
 .hConList  - handle of contrast selection ListBox
 .hDesMtxAx - handle of axes for design matrix imaging
 .hPrompt   - handle of prompt text object
 .hSTATmode - handle of frame containing "T/F/All" radio buttons
 .hStatLin  - handle of status line text object (in selection interface)
 .hNew      - handle of "Define new contrast" pushbutton
_______________________________________________________________________


 MarsBaR edits
 -------------
 The contrasts are stored in a stripped down mardo design structure, to
 allow this function to be called using object methods.  We need to return
 a flag (changef) to tell us if the contrasts have been changed by the GUI.
 This is stored in the D_Reset tagged handle (which is attached to the
 reset button).

 Edited from @(#)spm_conman.m    2.18 Andrew Holmes 02/09/10
 
 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout=ui_get_contrasts(D, varargin)
0002 % SPM contrast UI, wrapped for MarsBaR
0003 %
0004 %=======================================================================
0005 % - FORMAT specifications
0006 %=======================================================================
0007 %( This is a multi function function: If the first argument is a string,)
0008 %( then this is the action string, specifying the particular action     )
0009 %( function to take.                                                    )
0010 %
0011 % FORMAT [I,D,changef] = ui_get_contrasts(D,STATmode,n,Prompt,Mcstr,OK2chg)
0012 %
0013 % Takes design, offers contrast GUI, returns possibly modified design
0014 % Fields used in design are:
0015 %   xX         - Design Matrix structure
0016 %              - (see spm_spm.m for structure)
0017 %              - fields used directly are:
0018 %   .xKXs      - space structure of smoothed design matrix
0019 %   .name|xNames - cellstr of parameter names
0020 %
0021 %   xCon     - Contrast definitions structure array
0022 %                (see spm_FcUtil.m for structure, rules & handling)
0023 %              - defaults to empty contrast structure
0024 %              - fields used directly are:
0025 %   .name      - contrast name string
0026 %   .STAT      - character describing statistic required: 'T' or 'F'
0027 %   .c         - contrast weights (column) vector / matrix
0028 %
0029 % STATmode   - string indicating STAT modes to allow contrast
0030 %              selection/definition for:
0031 %            - 'T' to limit to (1-dimensional) contrasts defined for SPM{t}
0032 %            - 'F' to limit to contrasts defined for SPM{F}
0033 %            - 'T|F' to allow either contrasts for SPM{t} or SPM{F}
0034 %              (both may be defined, but only one type may be selected)
0035 %            - 'T&F' to allow both contrasts for SPM{t} and SPM{F}
0036 %            - defaults to 'T|F'
0037 %
0038 % n          - Number of contrasts to select, Inf for unlimited
0039 %
0040 % Prompt     - Prompt string
0041 %
0042 % Mcstr      - string to describe multiple contrast selection
0043 %              E.g. ' for conjunction' will result in the status message
0044 %                   reading 'Selected 2 contrasts for conjunction' when
0045 %                   two contrasts are selected.
0046 %
0047 % OK2chg     - logical, specifying whether the contrast structure can be
0048 %              changed. If false, then new contrasts cannot be defined, and
0049 %              existing contrasts cannot be renamed.
0050 %
0051 % I          - Index (or indices) of contrasts selected
0052 %
0053 % D (out)    - Design with modified contrast definitions structure array
0054 % changef    - flag set to 1 if contrast definitions have changed
0055 %
0056 %                           ----------------
0057 %
0058 % [F,cF] = ui_get_contrasts(D, 'Initialise',...
0059 %                              Vis,STATmode,n,Prompt,Mcstr,OK2chg)
0060 % Initialise mConMan GUI for contrast selection/definition
0061 % Vis        - Initialisation action:
0062 %              'close' - closes mConMan window
0063 %              'off'   - hides mConMan window
0064 %              'reset' - hides and resets mConMan window
0065 %              'on'    - initialises mConMan window using arguments given
0066 % STATmode   - string indicating STAT modes to allow contrast
0067 % n          - number of contrasts to select, Inf for unlimited
0068 % Prompt     - Prompt string
0069 % Mcstr      - string to describe multiple contrast selection
0070 % OK2chg     - logical, specifying whether contrast structure can be changed
0071 % F          - figure used for contrast manager window
0072 % cF         - Figure which was current before function call
0073 %
0074 % FORMAT ui_get_contrasts(D, 'ListCon',hConList,STAT,I)
0075 % Utility function to list contrasts in ListBox
0076 % hConList   - handle of GUI ListBox object
0077 % STAT       - STAT character: 'T' or 'F' or empty (show all)
0078 % I          - indices of currently selected contrasts
0079 %
0080 % FORMAT ui_get_contrasts(D, 'GraphCons',xCon,I,F)
0081 % Utility function to display contrast image/bar-graph & setup "surfing"
0082 % xCon       - contrast definitions structure array
0083 % I          - indicies of contrasts to display
0084 % F          - handle of 'mConMan' figure
0085 %
0086 % FORMAT ui_get_contrasts(D, 'StatusLine',F,str,col)
0087 % Utility function to update mConMan window statusline
0088 % F          - handle of 'mConMan' figure
0089 % str        - string to display
0090 %              (defaults to status of contrast selection)
0091 % col        - colour to use [defaults to 'w' - white
0092 %
0093 % FORMAT ui_get_contrasts(D, 'Done_CB')
0094 % CallBack for "Done" button on mConMan contrast selection interface
0095 %
0096 % FORMAT ui_get_contrasts(D, 'ConList_CB')
0097 % CallBack for contrast selection ListBox
0098 %
0099 % FORMAT STAT = ui_get_contrasts(D, 'TFA')
0100 % CallBack for 'T','F' or 'any' STAT selection RadioButtons
0101 % FORMAT STAT = ui_get_contrasts(D, 'TFA',F,STAT)
0102 % Initialisation of 'T','F' or 'any' STAT selection RadioButtons
0103 % FORMAT STAT = ui_get_contrasts(D, 'TFA',F,STAT,STATmode)
0104 % Function to set STAT & STATmode
0105 % Initialisation of 'T','F' or 'any' STAT selection RadioButtons & STATmode
0106 % F          - handle of 'mConMan' figure
0107 % STAT       - STAT character: 'T' or 'F' of empty (all)
0108 % STATmode   - string indicating STAT modes to allow contrast
0109 %
0110 % FORMAT ui_get_contrasts(D, 'FConMenu_CB')
0111 % CallBack to set state of mConMan contrast selection figure context menu
0112 %
0113 % FORMAT ui_get_contrasts(D, 'Rename_CB')
0114 % CallBack to handle contrast renaming
0115 %
0116 % FORMAT [c,I,emsg,imsg,msg] = ui_get_contrasts(D, 'ParseCon',cstr,X,STAT)
0117 % Contrast weights parser: Catch evaluation errors and invalid contrasts
0118 % cstr       - string (or cellstr) to evaluate to get contrast(s)
0119 % X          - design matrix
0120 % STAT       - 'T' or 'F' (for contrast checking)
0121 % c          - contrast weights matrix
0122 % I          - logical validity indicator: indicates which rows of
0123 %              cellstr(cstr) generated valid contrasts which were
0124 %              included in c
0125 % emsg       - cellstr of error messages produced during parsing
0126 % imsg       - cellstr of information messages for valid contrasts
0127 % msg        - cellstr of all messages produced during parsing,
0128 %              one cell per string in cstr
0129 %
0130 % FORMAT [iX0,I,emsg,imsg] = ui_get_contrasts(D, 'ParseIStr',str,max)
0131 % DesMtx column index parser: Catch eval errors and invalid indices
0132 % str        - string for evaluation to get column indices
0133 % max        - number of columns in design matrix
0134 % iX0        - vector of column indices: '!' if evaluation error
0135 % I          - 0 if evaluation error, 1 if evaluated OK
0136 % emsg       - error message
0137 %              (evaluation errors, non-integer indices, out of range indices)
0138 % imsg       - information message (valid indices)
0139 %
0140 % FORMAT ui_get_contrasts(D, 'Reset_CB')
0141 % CallBack handler for "reset" button on contrast selection interface
0142 %
0143 % FORMAT ui_get_contrasts(D, 'D_Setup_CB')
0144 % CallBack handler for "Define new" button:
0145 % Initialises Contrast Definition interface for use
0146 %
0147 % FORMAT ui_get_contrasts(D, 'D_ConMtx_CB')
0148 % CallBack handler for contrast weights definition widget
0149 % FORMAT ui_get_contrasts(D, 'D_X1cols_CB')
0150 % Callback handler for F-contrast "columns for reduced design" widget
0151 %
0152 % FORMAT ui_get_contrasts(D, 'D_Reset_CB')
0153 % CallBack handler for "reset" button on contrast definition interface
0154 %
0155 % FORMAT ui_get_contrasts(D, 'D_Cancel_CB')
0156 % CallBack handler for "cancel" button on contrast definition interface
0157 %
0158 % FORMAT ui_get_contrasts(D, 'D_OK_CB')
0159 % CallBack handler for "OK" button on contrast definiton interface
0160 %
0161 % FORMAT ui_get_contrasts(D, 'D_Status',F)
0162 % Set status line of contrast definition interface
0163 % F          - Handle of mConMan figure [defaults gcbf]
0164 %
0165 % FORMAT [F,H] = ui_get_contrasts(D, 'CreateFig')
0166 % Creates mConMan dialog figure (definition interface initially hidden)
0167 % F          - Handle of mConMan figure created
0168 % H          - Stricture of Handles:
0169 % .hConList  - handle of contrast selection ListBox
0170 % .hDesMtxAx - handle of axes for design matrix imaging
0171 % .hPrompt   - handle of prompt text object
0172 % .hSTATmode - handle of frame containing "T/F/All" radio buttons
0173 % .hStatLin  - handle of status line text object (in selection interface)
0174 % .hNew      - handle of "Define new contrast" pushbutton
0175 %_______________________________________________________________________
0176 %
0177 %
0178 % MarsBaR edits
0179 % -------------
0180 % The contrasts are stored in a stripped down mardo design structure, to
0181 % allow this function to be called using object methods.  We need to return
0182 % a flag (changef) to tell us if the contrasts have been changed by the GUI.
0183 % This is stored in the D_Reset tagged handle (which is attached to the
0184 % reset button).
0185 %
0186 % Edited from @(#)spm_conman.m    2.18 Andrew Holmes 02/09/10
0187 %
0188 % $Id$
0189   
0190 % simplify access to design
0191 xCon = get_contrasts(D);
0192 
0193 %-Parameters
0194 %=======================================================================
0195 COLOUR   = [.8,.8,1];    %-Question background colour
0196 PJump    = 1;        %-Jumping of pointer to mConMan window
0197 
0198 
0199 if (nargin<2) | ismember(varargin{1}, {'T', 'F', 'T|F', 'T&F'})
0200 %=======================================================================
0201 % [I,D,changef] = ui_get_contrasts(D,STATmode,n,Prompt,Mcstr,OK2chg)
0202 
0203 %-Condition arguments
0204 %-----------------------------------------------------------------------
0205 if nargin<6, OK2chg = 0; else, OK2chg=varargin{5}; end
0206 if nargin<5, Mcstr = ''; else, Mcstr=varargin{4}; end
0207 if nargin<4, Prompt='Select contrast(s)...'; else, Prompt=varargin{3}; end
0208 if nargin<3, n=1; else, n=varargin{2}; end
0209 if nargin<2, STATmode='T|F'; else, STATmode=varargin{1}; end
0210 
0211 %-----------------------------------------------------------------------
0212 
0213 %-Setup mConMan window & jump cursor
0214 [F,cF] = ui_get_contrasts(D, 'Initialise','on',STATmode,n,Prompt,Mcstr,OK2chg);
0215 if PJump
0216     PLoc = get(0,'PointerLocation');
0217     FRec = get(F,'Position');
0218     set(0,'PointerLocation',[FRec(1)+FRec(3)/2, FRec(2)+FRec(2)/2])
0219 end
0220 
0221 %-Wait until filenames have been selected
0222 hDone = findobj(F,'Tag','Done');
0223 waitfor(hDone,'UserData')
0224 
0225 %-Exit with error if mConManWin deleted
0226 if ~ishandle(hDone), error('Contrast Manager was quit!'), end
0227 
0228 %-Get xCon, I & exit status
0229 status   = get(hDone,'UserData');
0230 hConList = findobj(F,'Tag','ConList');
0231 Q        = get(hConList,'UserData');
0232 I        = Q(get(hConList,'Value'));
0233 changef  = get(findobj(F,'Tag','D_Reset'), 'UserData');
0234 
0235 % Set new contrasts, if modified
0236 if changef
0237     D = set_contrasts(D, get_contrasts(get(F,'UserData')), 0);
0238 end
0239 
0240 %-Reset and hide SelFileWin
0241 ui_get_contrasts(D, 'Initialise','off');
0242 
0243 %-Return focus to previous figure (if any)
0244 set(0,'CurrentFigure',cF)
0245 
0246 %-Jump cursor back to previous location
0247 if PJump, set(0,'PointerLocation',PLoc), end
0248 
0249 %-Exit with error if reset (status=-1)
0250 if status == -1, error(['reset: ',mfilename,' bailing out!']), end
0251 
0252 %-Output arguments
0253 varargout={I,D,changef};
0254 
0255 return
0256 end
0257 
0258 %=======================================================================
0259 % - Callbacks & Utility embedded functions
0260 %=======================================================================
0261 
0262 %=======================================================================
0263 switch lower(varargin{1}), case 'initialise'
0264 %=======================================================================
0265 % [F,cF] = ui_get_contrasts(D,'Initialise',Vis,STATmode,n,Prompt,Mcstr,OK2chg)
0266 
0267 if nargin<2, Vis='on'; else, Vis=varargin{2}; end
0268 
0269 %-Recover mConMan figure number (if it exists)
0270 F  = findobj(get(0,'Children'),'Flat','Tag','mConMan');
0271 
0272 cF = get(0,'CurrentFigure');                %-Save current figure
0273 
0274 switch lower(Vis), case 'close'
0275     close(F)
0276     varargout = {[],cF};
0277     return
0278 case {'off','reset'}
0279     varargout = {F,cF};                %-Return figure handles
0280     if isempty(F), return, end            %-Return if no mConMan win
0281     set(F,'Visible','off')                %-Make window Invisible
0282     if strcmp(lower(Vis),'reset')
0283         set(findobj(F,'Tag','Done'),'UserData',-1)
0284     end
0285     return
0286 case 'on'
0287     %-Sort out arguments
0288     %---------------------------------------------------------------
0289     if nargin<8, OK2chg = 0; else, OK2chg=varargin{7}; end
0290     if nargin<7, Mcstr = ''; else, Mcstr=varargin{6}; end
0291     Mcstr = cellstr(Mcstr); if length(Mcstr)<2, Mcstr{2}=''; end
0292     if nargin<6, Prompt='Select contrast(s)'; else, Prompt=varargin{5}; end
0293     if nargin<5, n=Inf; else, n=varargin{4}; end
0294     if nargin<4, STATmode='T&F'; else, STATmode=varargin{3}; end
0295 
0296     %-Create/find mConMan window
0297     %---------------------------------------------------------------
0298     if isempty(F)                    %-Create mConMan win
0299         [F,H] = ui_get_contrasts(D, 'CreateFig');
0300     else                        %-Get handles
0301         H.hDesMtxAx = findobj(F,'Tag','DesMtxAx');
0302         H.hParEstAx = findobj(F,'Tag','ParEstAx');
0303         H.hConList  = findobj(F,'Tag','ConList');
0304         H.hPrompt   = findobj(F,'Tag','Prompt');
0305         H.hTFAf     = findobj(F,'Tag','TFAf');
0306         H.hSTATmode = findobj(F,'Tag','STATmode');
0307         H.hStatLin  = findobj(F,'Tag','StatusLine');
0308         H.hNew      = findobj(F,'Tag','New');
0309     end
0310     varargout = {F,cF};                %-Return figure handles
0311     
0312     %-Set up xX for display etc
0313     %---------------------------------------------------------------
0314     SPM = des_struct(D);
0315     xX   = SPM.xX;
0316 
0317     %-Store required parameters in UserData of various objects
0318     %---------------------------------------------------------------
0319     tmpD = des_struct(D, struct('xCon', xCon));
0320     sf_SetD(tmpD, 0, F);
0321     set(H.hStatLin,        'UserData', Mcstr)    %-**
0322 
0323 
0324     % A little hack to make designs compatible between SPM 99 and 2
0325     if isfield(xX, 'Xnames'), xX.name = xX.Xnames; end
0326 
0327     %-Initialise interface
0328     %---------------------------------------------------------------
0329     set(findobj(F,'Tag','Done'),'UserData',0)    %-Init. Done UserData
0330     STAT = ui_get_contrasts(D, 'TFA',F,'',STATmode);%-Init. TFA buttons
0331     set(H.hPrompt,'String',Prompt,'UserData',n)    %-Set prompt
0332     sf_ImDesMtx(xX, H.hDesMtxAx)                %-Depict DesMtx
0333     sf_ImParEst(xX, H.hParEstAx)                %-Parameter estimability
0334     ui_get_contrasts(D, 'ListCon',H.hConList,STAT,[])    %-List contrasts
0335     if OK2chg, tmp='on'; else, tmp='off'; end    %-OK to change xCon?
0336     set(H.hNew,'Enable',tmp)            %-En/dis-able change UI
0337 %-****    if isempty(xCon), ui_get_contrasts(D); end    %-Go straight to DNewUI
0338 
0339     %-Popup figure, retaining CurrentFigure
0340     %---------------------------------------------------------------
0341     set(get(findobj(F,'Tag','DefineNew'),'UserData'),'Visible','off')
0342                             %-Hide define UI
0343     figure(F)                    %-PopUp figure
0344     set(0,'CurrentFigure',cF)            %-Return to prev. figure
0345     return
0346 
0347 otherwise
0348     error('Unrecognised ''Vis'' option')
0349 end
0350 
0351 
0352 %=======================================================================
0353 case 'listcon'
0354 %=======================================================================
0355 % ui_get_contrasts(D,'ListCon',hConList,STAT,I)
0356 
0357 hConList = varargin{2};
0358 STAT     = varargin{3};
0359 if nargin<5
0360     Q = get(hConList,'UserData');
0361     I = Q(get(hConList,'Value'));
0362 else
0363     I = varargin{4};
0364 end
0365 
0366 %-Sort out list, filtering by STAT, and display
0367 %-----------------------------------------------------------------------
0368 if isempty(xCon)
0369     Q = [];
0370 elseif isempty(STAT)
0371     Q = 1:length(xCon);
0372 else
0373     Q = find(strcmp({xCon(:).STAT},STAT));
0374 end
0375 
0376 q = find(ismember(Q,I));
0377 
0378 if ~isempty(Q)
0379     str        = cell(0);
0380     for i=1:length(Q)
0381         str{i} = sprintf('%03d {%c} : %s',...
0382                 Q(i),xCon(Q(i)).STAT,xCon(Q(i)).name);
0383     end
0384     FontAngle  = 'Normal';
0385     FontWeight = 'Normal';
0386     Enable     = 'on';
0387 else
0388     str        = ['no',deblank([' ',STAT]),' contrasts defined'];
0389     FontAngle  = 'Italic';
0390     FontWeight = 'Bold';
0391     Enable     = 'off';
0392 end
0393 
0394 set(hConList,'String',str,...
0395     'UserData',Q,...
0396     'Value',q,...
0397     'FontAngle',FontAngle,'FontWeight',FontWeight,...
0398     'Enable',Enable)
0399 
0400 ui_get_contrasts(D, 'GraphCons',xCon,Q(q),get(hConList,'Parent'))
0401 ui_get_contrasts(D, 'StatusLine',get(hConList,'Parent'))
0402 
0403 
0404 %=======================================================================
0405 case 'graphcons'
0406 %=======================================================================
0407 % ui_get_contrasts(D, 'GraphCons',xCon,I,F)
0408 
0409 if nargin>2, xCon=varargin{2}; end
0410 if nargin<4, I=[1:length(xCon)]; else, I=varargin{3}; end
0411 if nargin<5, F=[]; else, F=varargin{4}; end
0412 if isempty(F), F=spm_figure('FindWin','mConMan'); end
0413 if isempty(F), error('can''t find mConMan win'), end
0414 
0415 cF = get(0,'CurrentFigure');        %-Save current figure
0416 set(0,'CurrentFigure',F);        %-Make F current
0417 
0418 delete(findobj(F,'Tag','ConGrphAx'));
0419 
0420 
0421 %-Display contrasts
0422 %-----------------------------------------------------------------------
0423 if isempty(I)
0424     axes('Position',[0.65 (0.7 + .1*(1-0.9)) 0.3 .1*.9],...
0425         'Tag','ConGrphAx','Visible','off')
0426     text(0.5,0.5,'no contrast(s)',...
0427         'FontSize',spm('FontSize',8),...
0428         'FontAngle','Italic',...
0429         'HorizontalAlignment','Center',...
0430         'VerticalAlignment','Middle')
0431 
0432 else
0433 
0434     nPar   = size(xCon(1).c,1);
0435     xx     = [repmat([0:nPar-1],2,1);repmat([1:nPar],2,1)];
0436     nCon   = length(I);
0437     dy     = 0.2/max(nCon,2);
0438     hConAx = axes('Position',[0.65 (0.70 + dy*.1) 0.30 dy*(nCon-.1)],...
0439             'Tag','ConGrphAx','Visible','off');
0440     title('contrast(s)')
0441     htxt   = get(hConAx,'title'); set(htxt,'Visible','on')
0442 
0443     for ii = nCon:-1:1
0444         i  = abs(I(ii));
0445         axes('Position',[0.65 (0.7 + dy*(nCon-ii+.1)) 0.3 dy*.9])
0446         if xCon(i).STAT == 'T' & size(xCon(i).c,2)==1
0447         %-Single vector contrast for SPM{t} - bar
0448         yy = [zeros(1,nPar);repmat(xCon(i).c',2,1);zeros(1,nPar)];
0449         h = patch(xx,yy,[1,1,1]*.5);
0450         set(gca,'Tag','ConGrphAx',...
0451             'Box','off','TickDir','out',...
0452             'XTick',[],...
0453             'XLim',    [0,nPar],...
0454             'YTick',[-1,0,+1],'YTickLabel','',...
0455             'YLim',    [min(xCon(i).c),max(xCon(i).c)] + ...
0456                 [-1 +1] * max(abs(xCon(i).c))/10    )
0457         else
0458         %-F-contrast - image
0459         h = image((xCon(i).c'/max(abs(xCon(i).c(:)))+1)*32);
0460         set(gca,'Tag','ConGrphAx',...
0461             'Box','on','TickDir','out',...
0462             'XTick',[],...
0463             'XLim',    [0,nPar]+0.5,...
0464             'YTick',[0:size(xCon(i).c,2)]+0.5,'YTickLabel','',...
0465             'YLim',    [0,size(xCon(i).c,2)]+0.5    )
0466         end
0467         if I(ii)>0, ylabel(num2str(i)), end
0468         set(h,'ButtonDownFcn','spm_DesRep(''SurfCon_CB'')',...
0469           'UserData',    struct(    'i',        I(ii),...
0470                     'h',        htxt,...
0471                     'xCon',        xCon(i)))
0472     end
0473 end
0474 
0475 set(0,'CurrentFigure',cF)        %-Reset CurrentFigure to previous figure
0476 
0477 
0478 %=======================================================================
0479 case 'statusline'
0480 %=======================================================================
0481 % ui_get_contrasts(D, 'StatusLine',F,str,col)
0482 
0483 if nargin<3,    F = findobj(get(0,'Children'),'Flat','Tag','mConMan');
0484     else,    F = varargin{2}; end
0485 
0486 if nargin<4
0487     n = get(findobj(F,'Tag','Prompt'),'UserData');
0488     m = length(get(findobj(F,'Tag','ConList'),'Value'));
0489     
0490     str = sprintf('Selected %d contrast',m);
0491     if m~=1, str=[str,'s']; end
0492     
0493     Mcstr = get(findobj(F,'Tag','StatusLine'),'UserData');
0494     if m>1, str=[str,Mcstr{1}]; else, str=[str,Mcstr{2}]; end
0495     
0496     if m==0
0497         if n<0
0498             str = [str,', press "Done" when finished.'];
0499         else
0500             str = [str,'.'];
0501         end
0502     else
0503         if n==1
0504             str = [str,', press "Done".'];
0505         else
0506             str = [str,', press "Done" when finished.'];
0507         end
0508     end
0509 else
0510     str = varargin{3};
0511 end
0512 
0513 if nargin<5, col='w'; else, col=varargin{4}; end
0514 
0515 set(findobj(F,'Tag','StatusLine'),'String',str,'ForegroundColor',col)
0516 
0517 
0518 %=======================================================================
0519 case 'done_cb'
0520 %=======================================================================
0521 % ui_get_contrasts(D, 'Done_CB')
0522 
0523 F = gcbf;
0524 
0525 n = get(findobj(F,'Tag','Prompt'),'UserData');
0526 q = get(findobj(F,'Tag','ConList'),'Value');
0527 
0528 
0529 if n>0 & isempty(q)         %-Contrast(s) required, but none selected
0530     if n==1,            str = 'Select a contrast!';
0531     elseif isfinite(n), str = sprintf('Select %d contrasts!',n);
0532     else,               str = 'Select at least one contrast!';
0533     end
0534 elseif length(q)>abs(n)     %-Too many contrasts selected
0535     if n<0, tstr='at most'; else, tstr='only'; end
0536     if abs(n)==1,       str = ['Select',tstr,' one contrast!'];
0537     else,               str = sprintf('Select %s %d contrasts!',tstr,abs(n));
0538     end
0539 elseif n>0 & isfinite(n) & length(q)<n
0540     if n==1,            str = 'Select a contrast!';
0541     else,               str = sprintf('Select %d contrasts!',n);
0542     end
0543 else
0544     str = '';
0545 end
0546 
0547 if ~isempty(str)             %-error: display error dialog box
0548     spm('Beep')
0549     msgbox(str,sprintf('%s%s: %s...',spm('ver'),...
0550         spm('GetUser',' (%s)'),mfilename),'error','modal')
0551 else                         %-OK, set Done UserData tag for handling
0552     set(findobj(F,'Tag','Done'),'UserData',1)
0553 end
0554 
0555 
0556 %=======================================================================
0557 case 'conlist_cb'
0558 %=======================================================================
0559 % ui_get_contrasts(D, 'ConList_CB')
0560 
0561 F        = gcbf;
0562 hConList = gcbo;
0563 
0564 Q        = get(hConList,'UserData');
0565 I        = Q(get(hConList,'Value'));
0566 
0567 ui_get_contrasts(D, 'GraphCons',xCon,I,F)
0568 ui_get_contrasts(D, 'StatusLine',get(hConList,'Parent'))
0569 
0570 if strcmp(get(F,'SelectionType'),'open'), ui_get_contrasts(D, 'Done_CB'), end
0571 
0572 
0573 %=======================================================================
0574 case {'tfa','d_tf'}
0575 %=======================================================================
0576 % STAT = ui_get_contrasts(D, 'TFA')
0577 % STAT = ui_get_contrasts(D, 'TFA',F,STAT)
0578 % STAT = ui_get_contrasts(D, 'TFA',F,STAT,STATmode)
0579 
0580 DefNew = strcmp(lower(varargin{1}),'d_tf');        %-Handling DefineNew UI?
0581 
0582 if nargin<3, F = gcbf; else, F=varargin{2}; end
0583 
0584 if nargin<4                   %-Called as CallBack of T or F RadioButton
0585 %-----------------------------------------------------------------------
0586     h = gcbo;
0587     if get(h,'Value')==0
0588         %-Was selected - don't allow unselection
0589         set(h,'Value',1)
0590         varargout={get(h,'UserData')};
0591         return
0592     else
0593         %-Get new STAT
0594         STAT = get(h,'UserData');
0595     end
0596 else
0597     STAT = varargin{3};
0598 end
0599 
0600 if ~(nargin<5)                           %-Called to set STAT & STATmode
0601 %-----------------------------------------------------------------------
0602     STATmode = varargin{4};
0603     b_set = 1;
0604 else
0605     STATmode = get(findobj(F,'Tag','STATmode'),'UserData');
0606     b_set = 0;
0607 end
0608 
0609 
0610 %-Check STATmode & STAT, set temporary STATmode & STAT indicies
0611 %-----------------------------------------------------------------------
0612 STATinfo = struct(...                    %-STAT info structure
0613         'mode',        { 'T',  'F',  'T|F',    'T&F'},...
0614         'vSTAT',    {{'T'},{'F'},{'T','F'},{'T','F',''}},...
0615         'defSTAT',    { 'T',  'F',  'T',      ''},...
0616         'Enable',    {    {'on', 'off','off'},...
0617                     {'off','on' ,'off'},...
0618                     {'on', 'on', 'off'},...
0619                     {'on', 'on', 'on' }}    );
0620 i        = find(strcmp(STATmode,{STATinfo.mode}));    %-STATmode index
0621 if isempty(i), error('unknown STATmode'), end        %-Check STATmode valid
0622 if DefNew & i==4, i=3; end                    %-Treat 'T&F' as 'T|F'?
0623 if isempty(STAT), STAT=STATinfo(i).defSTAT; end        %-Set STAT as default(?)
0624 j        = find(strcmp(STAT,{'T','F',''}));        %-STAT index
0625 if isempty(j), error('unknown STAT'); end        %-Check known STAT
0626 if ~any(strcmp(STAT,STATinfo(i).vSTAT))            %-Check STAT is
0627     error('Invalid STAT for this STATmode')        % valid for
0628 end                            % this STATmode
0629 
0630 
0631 %-Set STAT buttons (& Dis/Enable according to STATmode if b_setEnable)
0632 %-----------------------------------------------------------------------
0633 if ~DefNew, Tag='TFA'; else, Tag='D_TF'; end
0634 H = flipud(findobj(F,'Tag',Tag));
0635 set(H(j),            'Value',1)
0636 set(H(setdiff([1:length(H)],j)),'Value',0)
0637 if b_set
0638     %-Set RadioButton 'Enable' & store STATmode
0639     set(findobj(F,'Tag','STATmode'),'UserData',STATmode)
0640     for k=1:length(H), set(H(k),'Enable',STATinfo(i).Enable{k}), end
0641 end
0642 
0643 
0644 if ~DefNew                    %-Additional UI setup for main contrast manager
0645 %-----------------------------------------------------------------------
0646 
0647     %-Reset ConList for new STAT if callback for TFA button
0648     %-------------------------------------------------------------------
0649     if nargin<3
0650         ui_get_contrasts(D, 'ListCon',findobj(F,'Tag','ConList'),STAT)
0651     end
0652 
0653 else     %-Additional UI setup for  DNew contrast definition interface
0654 %-----------------------------------------------------------------------
0655 
0656     %-Get handles of control objects
0657     %-------------------------------------------------------------------
0658     hD_ConMtx  = findobj(F,'Tag','D_ConMtx');
0659     hD_X1cols  = findobj(F,'Tag','D_X1cols');
0660     hD_ConErrs = findobj(F,'Tag','D_ConErrs');
0661     hD_ConInfo = findobj(F,'Tag','D_ConInfo');
0662     HD_Ttxt    = findobj(F,'Tag','D_Ttxt');
0663     HD_Ftxt    = findobj(F,'Tag','D_Ftxt');
0664     
0665     %-Set interface for new STAT
0666     %-------------------------------------------------------------------
0667     set(hD_ConMtx,'String',{},'UserData',[])            %-Clear ConMtx box
0668     set(hD_X1cols,'String','')                          %-Clear X1cols box
0669     set([hD_ConErrs,hD_ConInfo],'String',{},'Value',[]) %-Clear parsing boxes
0670     ui_get_contrasts(D, 'GraphCons',[],[],F)                     %-Clear contrast plot
0671     ui_get_contrasts(D, 'D_Status',F)                            %-Set StatusLine
0672     
0673     switch STAT
0674     case 'T'
0675         set(hD_ConMtx,'Max',1)
0676         set(HD_Ttxt,'Visible','on')
0677         set([hD_X1cols;HD_Ftxt],'Visible','off')
0678     case 'F'
0679         set(hD_ConMtx,'Max',2)
0680         set(HD_Ttxt,'Visible','off')
0681         set([hD_X1cols;HD_Ftxt],'Visible','on')
0682     otherwise
0683         error('illegal case')
0684     end
0685 
0686 end
0687 
0688 %-Return STAT
0689 %-----------------------------------------------------------------------
0690 varargout = {STAT};
0691 
0692 
0693 
0694 %=======================================================================
0695 case 'fconmenu_cb'
0696 %=======================================================================
0697 % ui_get_contrasts(D, 'FConMenu_CB')
0698 
0699 if strcmp(get(findobj(gcbf,'Tag','New'),'Enable'),'off')
0700     set(findobj(gcbo,'Tag','CM_New'),'Enable','off')
0701     set(findobj(gcbo,'Tag','CM_Ren'),'Enable','off')
0702 else
0703     set(findobj(gcbo,'Tag','CM_New'),'Enable','on')
0704     if length(get(findobj(gcbf,'Tag','ConList'),'Value'))==1
0705             set(findobj(gcbo,'Tag','CM_Ren'),'Enable','on')
0706     else
0707             set(findobj(gcbo,'Tag','CM_Ren'),'Enable','off')
0708     end
0709 end
0710 
0711 
0712 
0713 %=======================================================================
0714 case 'rename_cb'
0715 %=======================================================================
0716 % ui_get_contrasts(D, 'Rename_CB')
0717 
0718 F = gcbf;
0719 
0720 hConList = findobj(F,'Tag','ConList');
0721 Q        = get(hConList,'UserData');
0722 i        = get(hConList,'Value');
0723 
0724 %-Make sure there's only one selected contrast
0725 %-----------------------------------------------------------------------
0726 if length(i)~=1
0727     msgbox('Can only rename a single contrast!',...
0728         sprintf('%s%s: %s...',spm('ver'),...
0729         spm('GetUser',' (%s)'),mfilename),'error','modal')
0730     return
0731 end
0732 
0733 %-Get indices of current contrast
0734 %-----------------------------------------------------------------------
0735 I      = Q(i);
0736 
0737 %-Get new name
0738 %-----------------------------------------------------------------------
0739 str = sprintf('Enter new name for contrast %d (currently "%s"):',I,xCon(I).name);
0740 nname  = inputdlg(str,'SPM: Rename contrast',1,{''},'off');
0741 if isempty(nname), return, end
0742 
0743 %-Change name in ConList
0744 %-----------------------------------------------------------------------
0745 tmp    = get(hConList,'String');
0746 tmp{i} = strrep(tmp{i},xCon(I).name,nname{1});
0747 set(hConList,'String',tmp)
0748 
0749 %-Change name in contrast structure
0750 %-----------------------------------------------------------------------
0751 xCon(I).name = nname{1};
0752 D = set_contrasts(D, xCon, 0);
0753 sf_SetD(D, 1, F);
0754 
0755 
0756 %=======================================================================
0757 case 'parsecon'                       %-Parse (cell)string into contrast
0758 %=======================================================================
0759 % [c,I,emsg,imsg,msg] = ui_get_contrasts(D, 'ParseCon',cstr,X,STAT)
0760 % X is raw DesMtx or space structure
0761 
0762 %-Sort out parameters
0763 %-----------------------------------------------------------------------
0764 if nargin<5, STAT='F'; else, STAT=varargin{4}; end
0765 cstr = varargin{2};
0766 X    = varargin{3};
0767 p    = spm_SpUtil('size',X,2);
0768 
0769 %-Preliminary parsing of contrast string (cstr) into cellstr
0770 %-----------------------------------------------------------------------
0771 if isempty(cstr)
0772     varargout = {[],0,{'    <- !empty input'},{},{}};
0773     return
0774 elseif iscell(cstr)
0775     if size(cstr,1)~=1, cstr=cstr(:); end
0776     c    = cstr;
0777 elseif isstr(cstr)
0778     cstr = cellstr(cstr);
0779     c    = cstr;
0780 elseif isnumeric(cstr)
0781     if ndims(cstr)>2, error('matrices only!'), end
0782     c    = num2cell(cstr,2);
0783     cstr = cell(size(c));
0784     for i=1:prod(size(c)), cstr{i}=num2str(c{i}); end
0785 else
0786     error('contrast input must be string or number')
0787 end
0788 
0789 
0790 %-Evaluate individual lines of contrast matrix input
0791 %-----------------------------------------------------------------------
0792 I   = zeros(size(c,1),1);
0793 msg = cell(size(c)); [msg{:}] = deal(' (OK)');
0794 for i=1:size(c,1)
0795     if isstr(c{i})
0796         c{i} = evalin('base',['[',c{i},']'],'''!''');
0797     end
0798     if isstr(c{i})
0799         msg{i} = '!evaluation error';
0800     else
0801         if isempty(c{i})
0802             msg{i}=' (empty line  - ignored)';
0803         elseif all(c{i}(:)==0)
0804             if size(c{i},1)==1, str='vector'; else, str='matrix'; end
0805             c{i}=[]; msg{i}=[' (zero ',str,' - ignored)'];
0806         elseif STAT=='T' & size(c{i},1)>1
0807             c{i}='!'; msg{i}='!vector required';
0808         elseif size(c{i},2)>p
0809             c{i}='!'; msg{i}=sprintf('!too long - only %d prams',p);
0810         else
0811             if size(c{i},2)<p
0812                 tmp = p-size(c{i},2);
0813                 c{i}=[c{i}, zeros(size(c{i},1),tmp)];
0814                 if size(c{i},1)>1, str=' column'; else, str=''; end
0815                 if tmp>1,          str=[str,'s']; end
0816                 msg{i} = sprintf(' (right padded with %d zero%s)',tmp,str);
0817             end
0818             if ~spm_SpUtil('allCon',X,c{i}')
0819                 c{i}='!'; msg{i}='!invalid contrast';
0820             end
0821         end
0822     end
0823     I(i)=~isstr(c{i});
0824 end
0825 
0826 %-Construct contrast matrix, validity indicator, and collate parsing messages
0827 %-----------------------------------------------------------------------
0828 c    = cat(1,c{find(I)});
0829 msg  = [char(cstr), repmat('  <-  ',size(msg,1),1), char(msg)];
0830 emsg = msg(find(~I),:);
0831 imsg = msg(find( I),:);
0832 
0833 if all(I) & STAT=='T' & size(c,1)>1      %-Check for vector t-contrasts!
0834     I=zeros(size(I)); emsg={'!vector required'}; imsg={};
0835 end
0836 
0837 %-Return arguments
0838 %-----------------------------------------------------------------------
0839 varargout = {c',I,emsg,imsg,msg};
0840 
0841 
0842 
0843 %=======================================================================
0844 case 'parseistr'                     %-Parse index string
0845 %=======================================================================
0846 % [iX0,I,emsg,imsg] = ui_get_contrasts(D, 'ParseIStr',str,max)
0847 % str should be a string (row)vector
0848 
0849 
0850 %-Sort out parameters
0851 %-----------------------------------------------------------------------
0852 str = varargin{2};
0853 mx  = varargin{3};
0854 
0855 
0856 %-Process input string
0857 %-----------------------------------------------------------------------
0858 I = evalin('base',['[',str,']'],'''!''');
0859 
0860 if isstr(I)
0861     varargout = {'!',0,[str,'  <- !evaluation error'],''};
0862     return
0863 end
0864 
0865 %-Construct list of valid indicies
0866 %-----------------------------------------------------------------------
0867 ok  = ismember(I(:)',[1:mx]);
0868 iX0 = I(ok);
0869 
0870 %-Construct diagnostic info messages
0871 %-----------------------------------------------------------------------
0872 str = ''; msg='';
0873 if any(ok)
0874     str = strvcat(str,num2str(I(ok)));
0875     msg = strvcat(msg,'  <-  (OK)');
0876 end
0877 tmp = ( I<1 | I>mx );            %-Out of range
0878 if any(tmp)
0879     str = strvcat(str,num2str(I(tmp)));
0880     msg = strvcat(msg,sprintf('  <-  (ignored - not in [1:%d]',mx));
0881 end
0882 tmp = ( ~tmp & ~ok );            %-Non integer in range
0883 if any(tmp)
0884     str = strvcat(str,num2str(I(tmp)));
0885     msg = strvcat(msg,'  <-  (ignored - non-integer)');
0886 end
0887 
0888 %-Return arguments
0889 %-----------------------------------------------------------------------
0890 varargout = {iX0,1,'',cellstr([str,msg])};
0891 
0892 
0893 %=======================================================================
0894 case 'reset_cb'
0895 %=======================================================================
0896 % ui_get_contrasts(D, 'Reset_CB')
0897 
0898 hConList = findobj(gcbf,'Tag','ConList');
0899 STAT     = get(findobj(gcbf,'Tag','TFA','Value',1),'UserData');
0900 
0901 ui_get_contrasts(D,'ListCon',hConList,STAT,[])
0902 
0903 
0904 %=======================================================================
0905 case 'd_setup_cb'
0906 %=======================================================================
0907 % ui_get_contrasts(D, 'D_Setup_CB')
0908 
0909 F        = gcbf;
0910 STAT     = get(findobj(F,'Tag','TFA','Value',1),'UserData');
0911 STATmode = get(findobj(F,'Tag','STATmode'),'UserData');
0912 
0913 set(F,'UIContextMenu',[])                %-Disable Fig ContextMenu
0914 H = get(findobj(F,'Tag','DefineNew'),'UserData');    %-Get define UI handles
0915 set(findobj(H,'flat','Tag','D_name'),'String','')    %-Clear name
0916 %set(findobj(H,'flat','Tag','D_ConMtx'),'UserData',[])    %-Clear con definition
0917 set(H,'Visible','on')                    %-Show UI
0918 ui_get_contrasts(D, 'D_TF',F,STAT,STATmode);            %-Setup rest of define UI
0919 
0920 
0921 %=======================================================================
0922 case {'d_conmtx_cb','d_x1cols_cb'}
0923 %=======================================================================
0924 % ui_get_contrasts(D, 'D_ConMtx_CB')
0925 % ui_get_contrasts(D, 'D_X1cols_CB')
0926 
0927 fcn = find(strcmp(lower(varargin{1}),{'d_conmtx_cb','d_x1cols_cb'}));
0928 
0929 F   = gcbf;
0930 h   = gcbo;
0931 str = get(h,'String');
0932 
0933 hD_ConMtx  = findobj(F,'Tag','D_ConMtx');
0934 hD_X1cols  = findobj(F,'Tag','D_X1cols');
0935 
0936 
0937 %-Extract info from holding objects
0938 %-----------------------------------------------------------------------
0939 xX   = get(findobj(F,'Tag','DesMtxAx'),'UserData');
0940 STAT = get(findobj(F,'Tag','D_TF','Value',1),'UserData');
0941 
0942 
0943 if fcn==1                              %-Parse string from ConMtx widget
0944 %-----------------------------------------------------------------------
0945 
0946     set(hD_X1cols,'String','')
0947     [c,I,emsg,imsg] = ui_get_contrasts(D, 'ParseCon',str,xX.xKXs,STAT);
0948     if all(I)
0949         DxCon = spm_FcUtil('Set','',STAT,'c',c,xX.xKXs);
0950     else
0951         DxCon = [];
0952     end
0953 
0954 elseif fcn==2               %-Process column indicies from X1cols widget
0955 %-----------------------------------------------------------------------
0956     set(hD_ConMtx,'String','')
0957 
0958     nPar              = spm_SpUtil('size',xX.xKXs,2);
0959     [iX0,I,emsg,imsg] = ui_get_contrasts(D, 'ParseIStr',str,nPar);
0960 
0961     if I
0962         try    %-try-catch block for any errors in spm_FcUtil!
0963             DxCon = spm_FcUtil('Set','',STAT,'iX0',iX0,xX.xKXs);
0964             if STAT=='T' & size(DxCon.c,2)>1
0965                 I = 0; emsg = {'! t-contrasts must be vectors'};
0966             end
0967         catch
0968             I    = 0;
0969             emsg = lasterr;
0970         end
0971     end
0972 end
0973 
0974 
0975 %-Define the contrast or report errors...
0976 %-----------------------------------------------------------------------
0977 set(findobj(F,'Tag','D_ConErrs'),'String',emsg,'Value',[])
0978 set(findobj(F,'Tag','D_ConInfo'),'String',imsg,'Value',[])
0979 if all(I)
0980     set(hD_ConMtx,'UserData',DxCon);        %-Store contrast
0981     ui_get_contrasts(D, 'GraphCons',DxCon,-1,F)        %-Depict contrast
0982 else
0983     set(hD_ConMtx,'UserData',[]);            %-Clear contrast store
0984     ui_get_contrasts(D, 'GraphCons',[],[],F)            %-Clear contrast plot
0985 end
0986 ui_get_contrasts(D, 'D_Status',F)                %-Set StatusLine
0987 
0988 
0989 %=======================================================================
0990 case 'd_reset_cb'
0991 %=======================================================================
0992 % ui_get_contrasts(D, 'D_Reset_CB')
0993 
0994 STAT = get(findobj(gcbf,'Tag','TFA','Value',1),'UserData');
0995 set(findobj(gcbf,'Tag','D_name'),'String','')        %-Clear name
0996 set(findobj(gcbf,'Tag','D_ConMtx'),'UserData',[])    %-Contrast definition
0997 ui_get_contrasts(D, 'D_TF',gcbf,STAT);                %-Setup rest of define UI
0998 
0999 
1000 %=======================================================================
1001 case 'd_cancel_cb'
1002 %=======================================================================
1003 % ui_get_contrasts(D, 'D_Cancel_CB')
1004 
1005 set(get(findobj(gcbf,'Tag','DefineNew'),'UserData'),'Visible','off')
1006 set(gcbf,'UIContextMenu',findobj(gcbf,'Tag','mConMan_ConMen'))
1007 ui_get_contrasts(D, 'StatusLine')
1008 
1009 
1010 %=======================================================================
1011 case 'd_ok_cb'
1012 %=======================================================================
1013 % ui_get_contrasts(D, 'D_OK_CB')
1014 
1015 F = gcbf;
1016 
1017 name  = get(findobj(F,'Tag','D_name'),'String');
1018 DxCon = get(findobj(F,'Tag','D_ConMtx'),'UserData');
1019 STAT  = get(findobj(F,'Tag','D_TF','Value',1),'UserData');
1020 
1021 dNam = ~isempty(name);
1022 dCon = ~isempty(DxCon);
1023 
1024 if ~(dNam & dCon)
1025     spm('Beep')
1026     str = {    'contrast name not defined!','',...
1027         'no valid contrast defined!',''};
1028     msgbox(str([dNam+1,dCon+3]),...
1029         sprintf('%s%s: %s...',spm('ver'),...
1030         spm('GetUser',' (%s)'),mfilename),'error','modal')
1031     return
1032 end
1033 
1034 
1035 %-Append new contrast to xCon structure of mConMan figure 'UserData'
1036 %-----------------------------------------------------------------------
1037 DxCon.name = name;
1038 if ~strcmp(DxCon.STAT,STAT), error('STAT & DxCon.STAT mismatch!'), end
1039 if isempty(xCon)
1040     xCon = DxCon;
1041 else
1042     xCon = [xCon, DxCon];
1043 end
1044 D = set_contrasts(D, xCon, 0);
1045 sf_SetD(D, 1, F);
1046 
1047 
1048 %-Redisplay the new list of contrasts, with the new one selected
1049 %-----------------------------------------------------------------------
1050 hConList = findobj(F,'Tag','ConList');
1051 I = length(xCon);
1052 
1053 %-Use this code to add the new contrast to a multiple selection, if allowed
1054 % Q        = get(hConList,'UserData');
1055 % I        = Q(get(hConList,'Value'));
1056 % n        = get(findobj(F,'Tag','Prompt'),'UserData');
1057 % if abs(n)>1, I=[I,length(xCon)]; else, I=length(xCon); end
1058 
1059 ui_get_contrasts(D, 'TFA',F,xCon(end).STAT);            %-Set STAT
1060 ui_get_contrasts(D, 'ListCon',hConList,xCon(end).STAT,I)    %-ListCon
1061 
1062 %-Hide the DefineNew UI
1063 %-----------------------------------------------------------------------
1064 set(get(findobj(gcbf,'Tag','DefineNew'),'UserData'),'Visible','off')
1065 set(gcbf,'UIContextMenu',findobj(gcbf,'Tag','mConMan_ConMen'))
1066 
1067 
1068 %=======================================================================
1069 case 'd_status'
1070 %=======================================================================
1071 % ui_get_contrasts(D, 'D_Status',F)
1072 
1073 if nargin<3, F=gcbf; else, F=varargin{2}; end
1074 str  = {' not',''};
1075 dNam = ~isempty(get(findobj(F,'Tag','D_name'),'String'));
1076 dCon = ~isempty(get(findobj(F,'Tag','D_ConMtx'),'UserData'));
1077 if dNam & dCon, ok='on'; col='g'; else, ok='off'; col='w'; end
1078 ui_get_contrasts(D, 'StatusLine',F,...
1079     sprintf('name%s defined, contrast%s defined',str{dNam+1},str{dCon+1}),...
1080     col)
1081 %set(findobj(F,'Tag','D_OK'),'Enable',ok)        %-Enable "OK" button?
1082 
1083 
1084 %=======================================================================
1085 case 'createfig'
1086 %=======================================================================
1087 % [F,H] = ui_get_contrasts(D, 'CreateFig')
1088 % Handle Structure - H.{hConList,hDesMtxAx,hPrompt,hSTATmode,hStatLin,hNew}
1089 
1090 cF = get(0,'CurrentFigure');        %-Save current figure
1091 
1092 %-Generic callBack code.  Fetches object for method calls in callbacks
1093 %-----------------------------------------------------------------------
1094 cb = 'conD = get(findobj(''Tag'', ''mConMan''),''UserData''); ';
1095 
1096 %-Create window, compute scaling for screen size
1097 %-----------------------------------------------------------------------
1098 WS = spm('WinScale');                %-Window scaling factors
1099 FS = spm('FontSizes');                %-Scaled font sizes
1100 PF = spm_platform('fonts');            %-Font names (for this platform)
1101 S0 = get(0,'ScreenSize');            %-Screen size
1102 
1103 F = figure('IntegerHandle','off',...
1104         'Tag','mConMan',...
1105         'Name','SPM contrast manager','NumberTitle','off',...
1106         'Position',[S0(3)/2,S0(4)/2,0,0] + [-250,-200,500,400].*WS,...
1107         'Resize','off',...
1108         'Color',[1 1 1]*.7,...
1109         'MenuBar','none',...
1110         'DefaultTextColor','k',...
1111         'DefaultTextFontName',PF.helvetica,...
1112         'DefaultTextFontSize',FS(10),...
1113         'DefaultAxesFontName',PF.helvetica,...
1114         'DefaultUicontrolBackgroundColor',[1 1 1]*.7,...
1115         'DefaultUicontrolFontName',PF.helvetica,...
1116         'DefaultUicontrolFontSize',FS(10),...
1117         'DefaultUicontrolInterruptible','on',...
1118         'Colormap',gray(64),...
1119         'Renderer','painters',...
1120         'Visible','off');
1121 
1122 %-Draw GUI objects
1123 %-----------------------------------------------------------------------
1124 hPrompt = uicontrol(F,'Style','Text','Tag','Prompt','UserData',[],...
1125         'String','<Prompt not set yet>',...
1126         'FontName',PF.times,...
1127         'FontWeight','Bold',...
1128         'FontAngle','Italic',...
1129         'FontSize',FS(16),...
1130         'ForegroundColor','k',...
1131         'BackgroundColor',[1,1,1]*.7,...
1132         'HorizontalAlignment','Center',...
1133         'Position',[020 370 280 025].*WS);
1134 
1135 %                           ----------------
1136 %-T/F/all buttons...
1137 
1138 hSTATmode = uicontrol(F,'Style','Frame','Tag','STATmode',...
1139         'Position',[040 340 260 028].*WS);
1140 uicontrol(F,'Style','Text','String','show',...
1141         'FontName',PF.times,'FontAngle','Italic','FontSize',FS(8),...
1142         'ForegroundColor','w',...
1143         'Position',[045 365 030 010].*WS);
1144 hT = uicontrol(F,'Style','RadioButton','String','t-contrasts','Tag','TFA',...
1145         'ToolTipString','...to show only contrasts for SPM{t}',...
1146         'FontSize',FS(9),...
1147         'ForegroundColor','k',...
1148         'UserData','T',...
1149         'Position',[044 343 105 020].*WS);
1150 hF = uicontrol(F,'Style','RadioButton','String','F-contrasts','Tag','TFA',...
1151         'ToolTipString','...to show only contrasts for SPM{F}',...
1152         'FontSize',FS(9),...
1153         'ForegroundColor','k',...
1154         'UserData','F',...
1155         'Position',[149 343 105 020].*WS);
1156 hA = uicontrol(F,'Style','RadioButton','String','all','Tag','TFA',...
1157         'ToolTipString','...to show all defined contrasts',...
1158         'FontSize',FS(9),...
1159         'ForegroundColor','k',...
1160         'UserData','',...
1161         'Position',[254 343 041 020].*WS);
1162 set([hT,hF,hA],'CallBack',[cb 'ui_get_contrasts(conD, ''TFA'');'],...
1163         'Interruptible','off','BusyAction','Queue')
1164 
1165 
1166 %                           ----------------
1167 %-Contrast list...
1168 
1169 uicontrol(F,'Style','Text','Tag','ConListHdr',...
1170         'String','### {type} : name',...
1171         'FontSize',FS(8),'FontAngle','Italic',...
1172         'HorizontalAlignment','Left',...
1173         'BackgroundColor','w',...
1174         'Position',[042 320 256 016].*WS);
1175 
1176 hConList = uicontrol(F,'Style','ListBox','Tag','ConList',...
1177         'ToolTipString',['Select contrast(s) - drag/shift-click',...
1178             '/ctrl-click to select multiple contrasts'],...
1179         'String',{'list','not','set','yet'},...
1180         'Max',2,...
1181         'CallBack',[cb 'ui_get_contrasts(conD, ''ConList_CB'')'],...
1182         'Interruptible','off','BusyAction','Queue',...
1183         'BackgroundColor','w',...
1184         'Position',[040 080 260 240].*WS);
1185 
1186 %                           ----------------
1187 %-Control buttons & status area...
1188 
1189 hNew = uicontrol(F,'Style','Pushbutton','String','Define new contrast...',...
1190         'Tag','New',...
1191         'ToolTipString','define new contrast',...
1192         'ForegroundColor','b',...
1193         'Callback',[cb 'ui_get_contrasts(conD, ''D_Setup_CB'')'],...
1194         'Enable','on',...
1195         'Position',[040 050 150 022].*WS);
1196 
1197 uicontrol(F,'Style','Pushbutton','String','Reset',...
1198         'ToolTipString','reset selection',...
1199         'ForegroundColor','r',...
1200         'Callback',[cb 'ui_get_contrasts(conD, ''Reset_CB'')'],...
1201         'Position',[195 050 050 022].*WS);
1202 
1203 uicontrol(F,'Style','Pushbutton','String','Done',...
1204         'ToolTipString','done - press when selected contrast(s)',...
1205         'ForegroundColor','m',...
1206         'Tag','Done','UserData',1,...
1207         'Callback',[cb 'ui_get_contrasts(conD, ''Done_CB'')'],...
1208         'Interruptible','off','BusyAction','Cancel',...
1209         'Position',[250 050 050 022].*WS);
1210 
1211 uicontrol(F,'Style','Frame','Tag','StatusArea',...
1212     'Position',[010 010 480 030].*WS);
1213 
1214 if exist('spm_help.m')==2
1215     uicontrol(F,'Style','Pushbutton','String','?',...
1216         'ToolTipString','help on contrasts and the contrast manager',...
1217         'ForegroundColor','g',...
1218         'Callback','spm_help(''spm_conman.m'')',...
1219         'Position',[460 015 020 020].*WS);
1220 end
1221 
1222 hStatLin = uicontrol(F,'Style','Text','Tag','StatusLine',...
1223     'String','<Not set yet>',...
1224     'FontAngle','Italic',...
1225     'HorizontalAlignment','Center',...
1226     'ForegroundColor','w',...
1227     'Position',[020 015 430 020].*WS);
1228 
1229 %                           ----------------
1230 %-Axes for design matrix and parameter estimability...
1231 
1232 hDesMtxAx = axes('Parent',F,'Tag','DesMtxAx',...
1233         'Position',[0.65 0.30 0.30 0.40],...
1234         'Color','w',...
1235         'Box','on','XTick',[],'YTick',[]);
1236 
1237 hParEstAx = axes('Parent',F,'Tag','ParEstAx',...
1238         'Position',[0.65 0.18 0.30 0.05],...
1239         'Color','w',...
1240         'Box','on','XTick',[],'YTick',[]);
1241 
1242 %                           ----------------
1243 %-Figure UICOntextMenu
1244 
1245 h = uicontextmenu('Tag','mConMan_ConMen');
1246 set(F,'UIContextMenu',h)
1247 uimenu(h,'Label','Define new contrast...',...
1248     'Tag','CM_New',...
1249     'CallBack',[cb 'ui_get_contrasts(conD, ''D_Setup_CB'')'],...
1250     'Interruptible','off','BusyAction','Cancel');
1251 uimenu(h,'Label','Rename selected contrast...',...
1252     'Tag','CM_Ren',...
1253     'CallBack',[cb 'ui_get_contrasts(conD, ''Rename_CB'')'],...
1254     'Interruptible','off','BusyAction','Cancel');
1255 uimenu(h,'Label','Reset','Separator','on',...
1256     'CallBack',[cb 'ui_get_contrasts(conD, ''Reset_CB'')'],...
1257     'Interruptible','off','BusyAction','Cancel');
1258 uimenu(h,'Label','Done',...
1259     'CallBack',[cb 'ui_get_contrasts(conD, ''Done_CB'')'],...
1260     'Interruptible','off','BusyAction','Cancel');
1261 uimenu(h,'Label','help','Separator','on',...
1262     'CallBack','spm_help(''spm_conman'')',...
1263     'Interruptible','off','BusyAction','Cancel');
1264 uimenu(h,'Label','crash out','Separator','on',...
1265     'CallBack',[cb 'ui_get_contrasts(conD, ''Initialise'',''reset'');'],...
1266     'Interruptible','off','BusyAction','Cancel');
1267 set(h,'CallBack',[cb 'ui_get_contrasts(conD, ''FConMenu_CB'')'],...
1268     'Interruptible','off','BusyAction','Cancel');
1269     
1270 
1271 %-Draw contrast definition GUI
1272 %-----------------------------------------------------------------------
1273 H = [];                %-Save handles for visibility switching
1274 
1275 h = uicontrol(F,'Style','Frame','Tag','DefineNew',...
1276     'Position',[010 045 300 350].*WS);
1277 H = [H,h];
1278 h = uicontrol(F,'Style','Text','Tag','D_Prompt','UserData',[],...
1279         'String','define contrast...',...
1280         'FontName',PF.times,...
1281         'FontWeight','Bold',...
1282         'FontAngle','Italic',...
1283         'FontSize',FS(14),...
1284         'ForegroundColor','b',...
1285         'HorizontalAlignment','Center',...
1286         'Position',[020 360 280 030].*WS);
1287 H = [H,h];
1288 
1289 %                           ----------------
1290 %-name
1291 h = uicontrol(F,'Style','Frame','Position',[020 335 280 033].*WS);
1292 H = [H,h];
1293 h = uicontrol(F,'Style','Text','String','name',...
1294         'FontSize',FS(10),...
1295         'FontAngle','Italic',...
1296         'ForegroundColor','w',...
1297         'HorizontalAlignment','Center',...
1298         'Position',[025 355 045 020].*WS);
1299 H = [H,h];
1300 h = uicontrol(F,'Style','Edit','Tag','D_name',...
1301         'ToolTipString','enter name for contrast',...
1302         'HorizontalAlignment','Left',...
1303         'BackgroundColor',COLOUR,...
1304             'Callback',[cb 'ui_get_contrasts(conD, ''D_Status'')'],...
1305             'Interruptible','off',...
1306         'Position',[080 340 215 022].*WS);
1307 H = [H,h];
1308 
1309 %                           ----------------
1310 %-type
1311 h = uicontrol(F,'Style','Frame','Position',[020 295 280 033].*WS);
1312 H = [H,h];
1313 h = uicontrol(F,'Style','Text','String','type',...
1314         'FontSize',FS(10),...
1315         'FontAngle','Italic',...
1316         'ForegroundColor','w',...
1317         'HorizontalAlignment','Center',...
1318         'Position',[025 315 040 020].*WS);
1319 H = [H,h];
1320 
1321 hDT = uicontrol(F,'Style','RadioButton','String','t-contrast','Tag','D_TF',...
1322         'ToolTipString','...to define contrast for SPM{t}',...
1323         'FontSize',FS(9),...
1324         'ForegroundColor','k',...
1325         'UserData','T',...
1326         'Position',[080 300 105 022].*WS);
1327 hDF = uicontrol(F,'Style','RadioButton','String','F-contrast','Tag','D_TF',...
1328         'ToolTipString','...to define contrast for SPM{F}',...
1329         'FontSize',FS(9),...
1330         'ForegroundColor','k',...
1331         'UserData','F',...
1332         'Position',[190 300 105 022].*WS);
1333 set([hDT,hDF],'CallBack',[cb 'ui_get_contrasts(conD, ''D_TF'');'],...
1334         'Interruptible','off','BusyAction','Queue')
1335 H = [H,hDT,hDF];
1336 
1337 %                           ----------------
1338 %-contrast
1339 h = uicontrol(F,'Style','Frame','Position',[020 080 280 208].*WS);
1340 H = [H,h];
1341 h = uicontrol(F,'Style','Text','String','contrast',...
1342         'FontSize',FS(10),...
1343         'FontAngle','Italic',...
1344         'ForegroundColor','w',...
1345         'HorizontalAlignment','Center',...
1346         'Position',[025 275 055 020].*WS);
1347 H = [H,h];
1348 h = uicontrol(F,'Style','Text','String','contrast',...
1349         'FontSize',FS(6),...
1350         'HorizontalAlignment','Right',...
1351         'Position',[030 255 045 008].*WS);
1352 H = [H,h];
1353 h = uicontrol(F,'Style','Text','String','weights',...
1354         'FontSize',FS(6),...
1355         'HorizontalAlignment','Right',...
1356         'Position',[030 245 045 008].*WS);
1357 H = [H,h];
1358 h = uicontrol(F,'Style','Text','String','vector','Tag','D_Ttxt',...
1359         'FontSize',FS(6),...
1360         'HorizontalAlignment','Right',...
1361         'Position',[030 235 045 008].*WS);
1362 H = [H,h];
1363 h = uicontrol(F,'Style','Text','String','matrix','Tag','D_Ftxt',...
1364         'FontSize',FS(6),...
1365         'HorizontalAlignment','Right',...
1366         'Position',[030 235 045 008].*WS);
1367 H = [H,h];
1368 h = uicontrol(F,'Style','Edit','Tag','D_ConMtx',...
1369         'ToolTipString','enter contrast',...
1370         'HorizontalAlignment','Left',...
1371         'BackgroundColor',COLOUR,...
1372         'Max',2,...
1373         'CallBack',[cb 'ui_get_contrasts(conD, ''D_ConMtx_CB'')'],...
1374         'Interruptible','off','BusyAction','Queue',...
1375         'UserData',[],...
1376         'Position',[080 200 215 082].*WS);
1377 H = [H,h];
1378 h = uicontrol(F,'Style','Text','String','or','Tag','D_Ftxt',...
1379         'FontAngle','Italic',...
1380         'FontSize',FS(6),...
1381         'HorizontalAlignment','Left',...
1382         'Position',[025 205 030 008].*WS);
1383 H = [H,h];
1384 h = uicontrol(F,'Style','Text','String','columns for','Tag','D_Ftxt',...
1385         'FontSize',FS(6),...
1386         'HorizontalAlignment','Right',...
1387         'Position',[022 190 070 008].*WS);
1388 H = [H,h];
1389 h = uicontrol(F,'Style','Text','String','reduced design','Tag','D_Ftxt',...
1390         'FontSize',FS(6),...
1391         'HorizontalAlignment','Right',...
1392         'Position',[022 180 070 008].*WS);
1393 H = [H,h];
1394 h = uicontrol(F,'Style','Edit','Tag','D_X1cols',...
1395         'ToolTipString',...
1396             'enter column indicies of reduced design matrix X0',...
1397         'HorizontalAlignment','Left',...
1398         'BackgroundColor',COLOUR,...
1399         'CallBack',[cb 'ui_get_contrasts(conD, ''D_X1cols_CB'')'],...
1400         'Interruptible','off','BusyAction','Queue',...
1401         'Position',[090 180 155 020].*WS);
1402 H = [H,h];
1403 h = uicontrol(F,'Style','Pushbutton','String','...submit',...
1404         'FontSize',FS(8),...
1405         'ForegroundColor','c',...
1406         'Position',[245 180 050 020].*WS);
1407 H = [H,h];
1408 
1409 %-Errors & info boxes...
1410 h = uicontrol(F,'Style','ListBox','Tag','D_ConErrs',...
1411         'ToolTipString','contrast parsing errors',...
1412         'FontName',PF.courier,'FontSize',FS(7),...
1413         'ForegroundColor','r',...
1414         'BackgroundColor',[1 1 1]*.7,...
1415         'Enable','on','Max',2,'Value',[],...
1416         'Position',[027 127 268 042].*WS);
1417 H = [H,h];
1418 h = uicontrol(F,'Style','ListBox','Tag','D_ConInfo',...
1419         'ToolTipString','contrast parsing info',...
1420         'FontName',PF.courier,'FontSize',FS(7),...
1421         'ForegroundColor','g',...
1422         'BackgroundColor',[1 1 1]*.7,...
1423         'Enable','on','Max',2,'Value',[],...
1424         'Position',[027 085 268 042].*WS);
1425 H = [H,h];
1426 
1427 %                           ----------------
1428 %-Control buttons & status area...
1429 h = uicontrol(F,'Style','Pushbutton','String','Reset',...
1430         'Tag','D_Reset',...
1431         'ToolTipString','reset definition interface',...
1432         'ForegroundColor','b',...
1433         'Callback',[cb 'ui_get_contrasts(conD, ''D_Reset_CB'')'],...
1434         'Interruptible','off','BusyAction','Cancel',...
1435         'Position',[140 053 050 022].*WS);
1436 H = [H,h];
1437 h = uicontrol(F,'Style','Pushbutton','String','Cancel',...
1438         'Tag','D_Cancel',...
1439         'ToolTipString','cancel contrast definition',...
1440         'ForegroundColor','r',...
1441         'Callback',[cb 'ui_get_contrasts(conD, ''D_Cancel_CB'')'],...
1442         'Interruptible','off','BusyAction','Cancel',...
1443         'Position',[195 053 050 022].*WS);
1444 H = [H,h];
1445 h = uicontrol(F,'Style','Pushbutton','String','OK',...
1446         'Tag','D_OK',...
1447         'ToolTipString','OK - press to accept newly defined contrast',...
1448         'ForegroundColor','m',...
1449         'Callback',[cb 'ui_get_contrasts(conD, ''D_OK_CB'')'],...
1450         'Interruptible','off','BusyAction','Cancel',...
1451         'Position',[250 053 050 022].*WS);
1452 H = [H,h];
1453 set(findobj(H,'flat','Tag','DefineNew'),'UserData',H)
1454 
1455 
1456 %-Finish up
1457 %-----------------------------------------------------------------------
1458 set(0,'CurrentFigure',cF)
1459 varargout = {F,struct(    'hConList',    hConList,...
1460             'hDesMtxAx',    hDesMtxAx,...
1461             'hParEstAx',    hParEstAx,...
1462             'hPrompt',    hPrompt,...
1463             'hSTATmode',    hSTATmode,...
1464             'hStatLin',    hStatLin,...
1465             'hNew',        hNew    )};
1466 
1467 
1468 %=======================================================================
1469 otherwise                                               %-unknown action
1470 %=======================================================================
1471 error(['Illegal Action string: ',varargin{1}])
1472 
1473 
1474 %=======================================================================
1475 end                                                            % - E N D
1476 return
1477 %=======================================================================
1478 
1479 
1480 %=======================================================================
1481 % Subfunctions
1482 %=======================================================================
1483 function sf_ImDesMtx(xX, h)
1484 %-Picture design matrix
1485 
1486 axes(h)
1487 if isfield(xX,'nKX') & ~isempty(xX.nKX)
1488     hDesMtxIm = image((xX.nKX+1)*32);
1489 else
1490     hDesMtxIm = image(...
1491         (spm_DesMtx('sca',xX.xKXs.X,xX.name)+1)*32);
1492 end
1493 set(h,'YTick',[],'XTick',[])            %-No Tick marks
1494 set(h,'Tag','DesMtxAx','UserData',xX)    %-Reset axis UserData after image
1495 xlabel('Design matrix')
1496 set(hDesMtxIm,'UserData',...
1497     struct('X',xX.xKXs.X,'Xnames',{xX.name}))
1498 set(hDesMtxIm,'ButtonDownFcn','spm_DesRep(''SurfDesMtx_CB'')')
1499 return
1500 
1501 function sf_ImParEst(xX, h)
1502 %-Picture design parameter estimability
1503 
1504 axes(h)
1505 est  = spm_SpUtil('IsCon',xX.xKXs);
1506 nPar = length(est);
1507 
1508 hParEstIm = image((est+1)*32);
1509 set(h,    'XLim',[0,nPar]+.5,'XTick',[1:nPar-1]+.5,'XTickLabel','',...
1510     'YLim',[0,1]+.5,'YDir','reverse','YTick',[],...
1511     'Box','on','TickDir','in','XGrid','on','GridLineStyle','-');
1512 xlabel('parameter estimability')
1513 set(h,'Tag','ParEstAx')            %-Reset 'Tag' after image cleared it
1514 set(hParEstIm,'UserData',struct('est',est,'Xnames',{xX.name}))
1515 set(hParEstIm,'ButtonDownFcn','spm_DesRep(''SurfEstIm_CB'')')
1516 return
1517 
1518 function sf_SetD(D, changef, F)
1519 % Sets new data into figure
1520 if nargin < 2, changef = 0; end
1521 if nargin < 3, F = get(findobj('Tag', 'mConMan'),'UserData'); end
1522 
1523 hD_Reset = findobj(F,'Tag','D_Reset');
1524 set(F, 'UserData', D);
1525 set(hD_Reset, 'UserData', changef);
1526 return  
1527   

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019