spm_conman.m 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  1. function varargout=spm_conman(varargin)
  2. % Contrast manager: GUI for defining valid contrasts
  3. % FORMAT varargout=spm_conman(varargin)
  4. % - An embedded callback, multi-function function
  5. % - For detailed programmers comments,
  6. % see format specifications in main body of program (below user help)
  7. %__________________________________________________________________________
  8. %
  9. % The contrast manager is a user interface for the selection and definition
  10. % of contrasts for a given SPM design. At present, the contrast manager
  11. % provides only interactive GUI facilities.
  12. %
  13. % See also: spm_getSPM.m, spm_contrasts.m
  14. %
  15. %==========================================================================
  16. % U s i n g t h e S P M C o n t r a s t M a n a g e r G U I
  17. %==========================================================================
  18. %
  19. % The contrast manager graphicsl user interface (GUI) is a dialog box for
  20. % the specification and selection of contrasts. The contrast selection
  21. % interface is presented initially, pressing the "Define new contrast..."
  22. % button pops up the contrast definition interface:
  23. %
  24. %__________________________________________________________________________
  25. % ConMan: Contrast selection interface
  26. %
  27. % The contrast selection interface consists of:
  28. %
  29. % * "Show" statistic type radio-buttons: "t-contrasts", "F-contrasts", "All":
  30. % Selects the types of contrast that are presented for selection in the
  31. % contrast selection list box. Depending on the use of the contrast
  32. % manager, some options may be unavailable.
  33. %
  34. % * List-box of currently defined contrasts.
  35. % Each contrast is listed by number, type ("T" or "F"), and name. Only
  36. % contrasts of types specified by the settings of the "show"
  37. % radiobuttons are shown.
  38. % Select contrasts by clicking on their entry in the list-box. To
  39. % select multiple contrasts (for conjunctions or masking, if
  40. % appropriate), the standard techniques of drag selection and
  41. % shift-clicking can be used for selecting a set of adjacent contrasts,
  42. % control-click to select individual contrasts separated in the list.
  43. % Selected contrasts are highlit in black.
  44. %
  45. % * Image of the design matrix:
  46. % A grey-scale representation of the design matrix, to aid interpretation
  47. % of the contrasts.
  48. %
  49. % The design matrix is "surfable": Clicking (and holding or dragging)
  50. % around the design matrix image reports the corresponding value of the
  51. % design matrix ('normal' click - "left" mouse button usually), the
  52. % image filename ('extend' mouse click - "middle" mouse), or parameter
  53. % name ('alt' click - "right" mouse). Double clicking the design matrix
  54. % image extracts the design matrix into the base MATLAB workspace.
  55. % (Surfing is handled by spm_DesRep.m)
  56. %
  57. % * Parameter estimability bar
  58. % Under the design matrix the parameter estimability is displayed as
  59. % a 1xp matrix of grey and white squares. Parameters that are not
  60. % uniquely specified by the model are shown with a grey patch.
  61. %
  62. % Recall that only uniquely estimable parameters can be examined
  63. % individually with [0,...,0,1,0,...,0] type contrats.
  64. %
  65. % Surfing the estimability image reports the parameter names and
  66. % their estimability. Double clicking extracts the estimability
  67. % vector into the base MatLab workspace.
  68. %
  69. % * Contrast weights plot/image:
  70. % The weights of the selected contrast(s) are imaged above the design
  71. % matrix, labelled by their contrast number. t-contrasts are displayed
  72. % as bar-charts, F-contrasts have their weights matrix c' depicted as a
  73. % grey-scale image.
  74. %
  75. % Again, the contrast representation is "surfable": Clicking and
  76. % dragging over the contrast image reports the contrast name, type and
  77. % number, and the value of the contrast at the mouse location.
  78. %
  79. % * "Define new contrast..." button:
  80. % Pops up the contrast definition interface (described below)
  81. %
  82. % * "Reset" button:
  83. % Clears the current contrast selection.
  84. %
  85. % * "Done" button:
  86. % Press when the required contrasts have been selected.
  87. %
  88. % * Status line:
  89. % This indicates how many contrasts have been selected, how
  90. % multi-contrast selections will be handled, and whether you can press
  91. % "Done" yet!
  92. %
  93. % In addition, the dialog has a figure ContextMenu, accessed by
  94. % right-clicking in the figure background: In addition to providing
  95. % repeats of the "Define new contrast...", "Reset" & "Done" buttons
  96. % described above, there are two additional options:
  97. %
  98. % - crash out: this bails out of the contrast manager in a nice way!
  99. % - rename: This permits a single contrast to be re-named. You
  100. % must select the contrast to be renamed before pulling
  101. % up the context menu for this option to be available.
  102. %
  103. %__________________________________________________________________________
  104. % ConMan: Contrast definition interface
  105. %
  106. % To define a contrast, you must specify:
  107. % 1) a name
  108. % 2) the statistic type: "t-contrast" for SPM{T} or "F-contrast" for SPM{F}
  109. % 3) a valid set of contrast weights
  110. % (for F-contrasts, this can also be generated given a reduced
  111. % (design as a partition of the existing design
  112. %
  113. % The contrast definition interface consists of:
  114. %
  115. % * A lilac "name" edit widget for naming the new contrast
  116. % Type the name of the contrast in this widget.
  117. % Press return or move the focus to enter the name.
  118. %
  119. % * Radio-buttons for selecting statistic type: "t-contrast" or "F-contrast"
  120. %
  121. % * A large lilac edit widget for entering "contrast weights matrix"
  122. % - Note that contrast weights should be entered transposed, with
  123. % contrast weights in rows.
  124. % - Zero's will be automatically added to the right hand side of
  125. % contrast weights as needed to give contrast weights matching the
  126. % number of parameters. For example, if you are interested in
  127. % contrasting the first two conditions of a design four parameters
  128. % (design matrix with 4 columns), you need only enter "+1 -1". The
  129. % contrast manager will parse this to [+1 -1 0 0].
  130. % - For t-contrasts, this will only accept a single line of input,
  131. % since contrast weights c' for an SPM{T} must be a row-vector.
  132. % Pressing <return> or moving the focus (by clicking on another GUI
  133. % element, such as the "Submit" button) will enter the contrast
  134. % weights for parsing.
  135. % - For F-contrasts, the widget accepts multi-line input.
  136. % Pressing <return> will move to a new line. Press <ctrl>-<return> or
  137. % move the focus (by clicking on another GUI element, such as the
  138. % "Submit" button) to enter the contrast weights for parsing.
  139. % - Text entered in the "contrast weights matrix" is evaluated in the
  140. % base workspace. Thus, matlab functions can be used in the widget,
  141. % and base workspace variables can be referred to. (See the help for
  142. % spm_input.m for more tips on using evaluated input widgets.)
  143. %
  144. % * For F-contrasts, a "columns for reduced design" edit widget appears:
  145. % - Here you can specify SPM{F}s by specifying the reduced design as
  146. % a sub-partition of the current design matrix.
  147. % - Enter the indicies of the design matrix columns you wish to retain
  148. % in the reduced design.
  149. % - Pressing <return> or moving the focus (by clicking on another GUI
  150. % element, such as the "Submit" button) will enter the column indicies
  151. % for parsing.
  152. % - An F-contrast weights matrix is constructed from the specified
  153. % partitioning. (The corresponding F-contrast weights are imaged
  154. % above the design matrix picture. Double click (or "surf") the
  155. % contrast image to see the actual values of the F-contrast weights
  156. % matrix.)
  157. % - Again, text entered in the "columns for reduced design" is
  158. % evaluated in the base workspace, permitting the use of functions
  159. % and variables available in the base workspace.
  160. % - (Note that the F-contrast weights matrix produced may not be the
  161. % simplest F-contrast possible for this test, and that the F-contrast
  162. % weights matrix may not be full rank (e.g. may have two rows where
  163. % one would do). Nontheless, the F-test is equivalent for the
  164. % specified partitioning.
  165. %
  166. % * "Submit" button:
  167. % This button can be used to force parsing of the contrast weights (or
  168. % columns for reduced design).
  169. %
  170. % * contrast parsing errors pane & contrast parsing info pane:
  171. % - Once the contrast weights matrix has been entered in the GUI, the
  172. % inout is parsed.
  173. % - First, each line is evaluated.
  174. % - Then, the results for each line are checked to ensure thay define
  175. % valid contrasts, with trailing zeros added as necessary so the
  176. % contrast length matches the number of parameters.
  177. % - Errors encountered during parsing, and invalid contrast weights,
  178. % are reported in the "contrast parsing errors" pane in red text.
  179. % Usually the contrast cannot be defined if there are any errors!
  180. % - Information messages regarding contrast parsing appear in the lower
  181. % "contrast parsing info" pane in green text.
  182. % - When defining an F-contrast via "columns for reduced design", the
  183. % string defining the indicies is similarly parsed, with errors and
  184. % information messages appearing in the two panes.
  185. %
  186. % * Contrast weights plot/image:
  187. % Depicts the contrast once valid contrast weights have been specified.
  188. %
  189. % * Image of the design matrix:
  190. % (As described above for the contrast selection interface)
  191. %
  192. % * Parameter estimability bar
  193. % (As described above for the contrast selection interface)
  194. %
  195. % * "Reset" button:
  196. % Resets the contrast definition interface, clearing any contrast
  197. % currently being defined.
  198. %
  199. % * "Cancel" button:
  200. % Returns to the contrast selection interface without defining a new
  201. % contrast.
  202. %
  203. % * "OK" button:
  204. % Once a valid set of contrast weights has been defined, and the
  205. % contrast named, pressing "OK" defines the contrast and returns to the
  206. % contrast selection interface, with the newly defined contrast
  207. % selected.
  208. %
  209. % * Status line:
  210. % This indicates progress in contrast definition.
  211. % Once a valid set of contrast weights have been specified, and a
  212. % the contrast named, then the status line turns green, indicating
  213. % that the current contrast can be defined by pressing "OK".
  214. %
  215. %
  216. %==========================================================================
  217. % S P M C o n t r a s t m a n a g e m e n t
  218. %==========================================================================
  219. %
  220. % Contrasts are stored by SPM in a single structure (See spm_FcUtil.m
  221. % for the definition and handling of the contrast structure.)
  222. %
  223. % Note that the xCon structure for each contrast contains data specific
  224. % to the current experimental design. Therefore, contrast structures
  225. % can only be copied between analyses (to save re-entering contrasts)
  226. % if the designs are *identical*.
  227. %
  228. % Although the contrasts are named by the user, they are referred to
  229. % internally and on the corresponding contrast, ESS and SPM images (see
  230. % spm_getSPM.m) by their contrast number, which indexes them in the
  231. % order in which they were created. Because of this, it can be rather
  232. % involved to delete any but the most recently defined contrast: All
  233. % file references and indices would have to be canonicalised! Thus, no
  234. % "delete" function is provided (as yet).
  235. %
  236. %__________________________________________________________________________
  237. % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
  238. % Andrew Holmes
  239. % $Id: spm_conman.m 5786 2013-12-06 18:25:00Z guillaume $
  240. %==========================================================================
  241. % - FORMAT specifications
  242. %==========================================================================
  243. %( This is a multi function function: If the first argument is a string,)
  244. %( then this is the action string, specifying the particular action )
  245. %( function to take. )
  246. %
  247. % FORMAT [I,xCon] = spm_conman(SPM,STATmode,n,Prompt,Mcstr,OK2chg)
  248. %
  249. % SPM.xX - Design Matrix structure
  250. % - (see spm_spm.m for structure)
  251. % - fields used directly are:
  252. % .xKXs - space structure of smoothed design matrix
  253. % .name - cellstr of parameter names
  254. %
  255. % SPM.xCon (in) - Contrast definitions structure array
  256. % (see spm_FcUtil.m for structure, rules & handling)
  257. % - defaults to empty contrast structure
  258. % - fields used directly are:
  259. % .name - contrast name string
  260. % .STAT - character describing statistic required: 'T' or 'F'
  261. % .c - contrast weights (column) vector / matrix
  262. %
  263. % STATmode - string indicating STAT modes to allow contrast
  264. % selection/definition for:
  265. % - 'T' to limit to contrasts defined for SPM{t}
  266. % - 'F' to limit to contrasts defined for SPM{F}
  267. % - 'T|F' to allow either contrasts for SPM{t} or SPM{F}
  268. % (both may be defined, but only one type may be selected)
  269. % - 'T&F' to allow both contrasts for SPM{t} and SPM{F}
  270. % - defaults to 'T|F'
  271. %
  272. % n - Number of contrasts to select, Inf for unlimited
  273. %
  274. % Prompt - Prompt string
  275. %
  276. % Mcstr - string to describe multiple contrast selection
  277. % E.g. ' for conjunction' will result in the status message
  278. % reading 'Selected 2 contrasts for conjunction' when
  279. % two contrasts are selected.
  280. %
  281. % OK2chg - logical, specifying whether the contrast structure can be
  282. % changed. If false, then new contrasts cannot be defined, and
  283. % existing contrasts cannot be renamed.
  284. %
  285. % I - Index (or indices) of contrasts selected
  286. %
  287. % xCon (out) - Contrast definitions structure array (updated)
  288. %
  289. % ----------------
  290. %
  291. % [F,cF] = spm_conman('Initialise',...
  292. % Vis,SPM,STATmode,n,Prompt,Mcstr,OK2chg)
  293. % Initialise ConMan GUI for contrast selection/definition
  294. % Vis - Initialisation action:
  295. % 'close' - closes ConMan window
  296. % 'off' - hides ConMan window
  297. % 'reset' - hides and resets ConMan window
  298. % 'on' - initialises ConMan window using arguments given
  299. % SPM.xX - design matrix structure
  300. % SPM.xCon - contrast definitions structure array
  301. % STATmode - string indicating STAT modes to allow contrast
  302. % n - number of contrasts to select, Inf for unlimited
  303. % Prompt - Prompt string
  304. % Mcstr - string to describe multiple contrast selection
  305. % OK2chg - logical, specifying whether contrast structure can be changed
  306. % F - figure used for contrast manager window
  307. % cF - Figure which was current before function call
  308. %
  309. % FORMAT spm_conman('ImDesMtx',xX,h)
  310. % Utility function to display design matrix image & setup "surfing"
  311. % xX - Design Matrix structure
  312. % - the first of {xX.nX, xX.xKXs.X} is used for display
  313. % .nX - Desgin matrix already scaled for display
  314. % .xKXs.X - temporally filtered design matrix (within space structure)
  315. % .name - px1 CellStr of parameter names
  316. %
  317. % FORMAT spm_conman('ImParEst',xX,h)
  318. % Utility function to display parameter estimability & setup "surfing"
  319. % xX - Design Matrix structure
  320. % xX.xKXs - space structure for K*X
  321. % xX.name - px1 CellStr of parameter names
  322. % h - handle of axes to use
  323. %
  324. % FORMAT spm_conman('ListCon',hConList,xCon,STAT,I)
  325. % Utility function to list contrasts in ListBox
  326. % hConList - handle of GUI ListBox object
  327. % xCon - current contrast definitions structure array
  328. % STAT - STAT character: 'T' or 'F' of empty (show all)
  329. % I - indicies of currently selected contrasts
  330. %
  331. % FORMAT spm_conman('GraphCons',xCon,I,F)
  332. % Utility function to display contrast image/bar-graph & setup "surfing"
  333. % xCon - contrast definitions structure array
  334. % I - indicies of contrasts to display
  335. % F - handle of 'ConMan' figure
  336. %
  337. % FORMAT spm_conman('StatusLine',F,str,col)
  338. % Utility function to update ConMan window statusline
  339. % F - handle of 'ConMan' figure
  340. % str - string to display
  341. % (defaults to status of contrast selection)
  342. % col - colour to use [defaults to 'w' - white
  343. %
  344. % FORMAT spm_conman('Done_CB')
  345. % CallBack for "Done" button on ConMan contrast selection interface
  346. %
  347. % FORMAT spm_conman('ConList_CB')
  348. % CallBack for contrast selection ListBox
  349. %
  350. % FORMAT STAT = spm_conman('TFA')
  351. % CallBack for 'T','F' or 'any' STAT selection RadioButtons
  352. % FORMAT STAT = spm_conman('TFA',F,STAT)
  353. % Initialisation of 'T','F' or 'any' STAT selection RadioButtons
  354. % FORMAT STAT = spm_conman('TFA',F,STAT,STATmode)
  355. % Function to set STAT & STATmode
  356. % Initialisation of 'T','F' or 'any' STAT selection RadioButtons & STATmode
  357. % F - handle of 'ConMan' figure
  358. % STAT - STAT character: 'T' or 'F' of empty (all)
  359. % STATmode - string indicating STAT modes to allow contrast
  360. %
  361. % FORMAT spm_conman('FConMenu_CB')
  362. % CallBack to set state of ConMan contrast selection figure context menu
  363. %
  364. % FORMAT spm_conman('Rename_CB')
  365. % CallBack to handle contrast renaming
  366. %
  367. % FORMAT [c,I,emsg,imsg,msg] = spm_conman('ParseCon',cstr,X,STAT)
  368. % Contrast weights parser: Catch evaluation errors and invalid contrasts
  369. % cstr - string (or cellstr) to evaluate to get contrast(s)
  370. % X - design matrix
  371. % STAT - 'T' or 'F' (for contrast checking)
  372. % c - contrast weights matrix
  373. % I - logical validity indicator: indicates which rows of
  374. % cellstr(cstr) generated valid contrasts which were
  375. % included in c
  376. % emsg - cellstr of error messages produced during parsing
  377. % imsg - cellstr of information messages for valid contrasts
  378. % msg - cellstr of all messages produced during parsing,
  379. % one cell per string in cstr
  380. %
  381. % FORMAT [iX0,I,emsg,imsg] = spm_conman('ParseIStr',str,max)
  382. % DesMtx column index parser: Catch eval errors and invalid indices
  383. % str - string for evaluation to get column indices
  384. % max - number of columns in design matrix
  385. % iX0 - vector of column indices: '!' if evaluation error
  386. % I - 0 if evaluation error, 1 if evaluated OK
  387. % emsg - error message
  388. % (evaluation errors, non-integer indices, out of range indices)
  389. % imsg - information message (valid indices)
  390. %
  391. % FORMAT spm_conman('Reset_CB')
  392. % CallBack handler for "reset" button on contrast selection interface
  393. %
  394. % FORMAT spm_conman('D_Setup_CB')
  395. % CallBack handler for "Define new" button:
  396. % Initialises Contrast Definition interface for use
  397. %
  398. % FORMAT spm_conman('D_ConMtx_CB')
  399. % CallBack handler for contrast weights definition widget
  400. % FORMAT spm_conman('D_X1cols_CB')
  401. % Callback handler for F-contrast "columns for reduced design" widget
  402. %
  403. % FORMAT spm_conman('D_Reset_CB')
  404. % CallBack handler for "reset" button on contrast definition interface
  405. %
  406. % FORMAT spm_conman('D_Cancel_CB')
  407. % CallBack handler for "cancel" button on contrast definition interface
  408. %
  409. % FORMAT spm_conman('D_OK_CB')
  410. % CallBack handler for "OK" button on contrast definiton interface
  411. %
  412. % FORMAT spm_conman('D_Status',F)
  413. % Set status line of contrast definition interface
  414. % F - Handle of ConMan figure [defaults gcbf]
  415. %
  416. % FORMAT [F,H] = spm_conman('CreateFig')
  417. % Creates ConMan dialog figure (definition interface initially hidden)
  418. % F - Handle of ConMan figure created
  419. % H - Stricture of Handles:
  420. % .hConList - handle of contrast selection ListBox
  421. % .hDesMtxAx - handle of axes for design matrix imaging
  422. % .hPrompt - handle of prompt text object
  423. % .hSTATmode - handle of frame containing "T/F/All" radio buttons
  424. % .hStatLin - handle of status line text object (in selection interface)
  425. % .hNew - handle of "Define new contrast" pushbutton
  426. %__________________________________________________________________________
  427. %-Parameters
  428. %==========================================================================
  429. COLOUR = [.8,.8,1]; %-Question background colour
  430. PJump = 1; %-Jumping of pointer to ConMan window
  431. %==========================================================================
  432. % [I,xCon] = spm_conman(SPM,STATmode,n,Prompt,Mcstr,OK2chg)
  433. %==========================================================================
  434. if (nargin==0) || ~ischar(varargin{1})
  435. %-Condition arguments
  436. %----------------------------------------------------------------------
  437. if nargin<6, OK2chg = 0; else OK2chg=varargin{6}; end
  438. if nargin<5, Mcstr = ''; else Mcstr=varargin{5}; end
  439. if nargin<4, Prompt='Select contrast(s)...'; else Prompt=varargin{4}; end
  440. if nargin<3, n=1; else n=varargin{3}; end
  441. if nargin<2, STATmode='T|F'; else STATmode=varargin{2}; end
  442. if nargin<1, error('no SPM struct specified'); else SPM = varargin{1};end
  443. %----------------------------------------------------------------------
  444. try
  445. SPM.xCon;
  446. catch
  447. SPM.xCon = {};
  448. end
  449. %-Setup ConMan window & jump cursor
  450. [F,cF] = spm_conman('Initialise','on',SPM,STATmode,n,Prompt,Mcstr,OK2chg);
  451. if PJump
  452. PLoc = get(0,'PointerLocation');
  453. FRec = get(F,'Position');
  454. set(0,'PointerLocation',[FRec(1)+FRec(3)/2, FRec(2)+FRec(2)/2])
  455. end
  456. %-Copy SPM structure for later change detecton, eg renamed contrasts
  457. tmpSPM = SPM;
  458. %-Wait until filenames have been selected
  459. hDone = findobj(F,'Tag','Done');
  460. waitfor(hDone,'UserData')
  461. %-Exit with error if ConManWin deleted
  462. if ~ishandle(hDone), error('Contrast Manager was quit!'), end
  463. %-Get xCon, I & exit status
  464. status = get(hDone,'UserData');
  465. hConList = findobj(F,'Tag','ConList');
  466. Q = get(hConList,'UserData');
  467. I = Q(get(hConList,'Value'));
  468. SPM = get(F,'UserData');
  469. xCon = SPM.xCon;
  470. %-Save SPM.mat only if SPM structure as changed
  471. if spm_check_version('matlab','8.0') >= 0, my_isequaln = @isequaln;
  472. else my_isequaln = @isequalwithequalnans; end
  473. if ~my_isequaln(tmpSPM,SPM)
  474. save('SPM.mat', 'SPM', spm_get_defaults('mat.format'));
  475. end
  476. %-Reset and hide SelFileWin
  477. spm_conman('Initialise','off');
  478. %-Return focus to previous figure (if any)
  479. set(0,'CurrentFigure',cF)
  480. %-Jump cursor back to previous location
  481. if PJump, set(0,'PointerLocation',PLoc), end
  482. %-Exit with error if reset (status=-1)
  483. if status == -1, error(['reset: ',mfilename,' bailing out!']), end
  484. %-Output arguments
  485. varargout={I,xCon};
  486. return
  487. end
  488. %==========================================================================
  489. % - Callbacks & Utility embedded functions
  490. %==========================================================================
  491. switch lower(varargin{1})
  492. %======================================================================
  493. case 'initialise'
  494. %======================================================================
  495. % [F,cF] = spm_conman('Initialise',Vis,SPM,STATmode,n,Prompt,Mcstr,OK2chg)
  496. if nargin<2, Vis='on'; else Vis=varargin{2}; end
  497. %-Recover ConMan figure handle (if it exists)
  498. F = findobj(get(0,'Children'),'Flat','Tag','ConMan');
  499. cF = get(0,'CurrentFigure'); %-Save current figure
  500. switch lower(Vis)
  501. %------------------------------------------------------------------
  502. case 'close'
  503. %------------------------------------------------------------------
  504. close(F)
  505. varargout = {[],cF};
  506. return
  507. %------------------------------------------------------------------
  508. case {'off','reset'}
  509. %------------------------------------------------------------------
  510. varargout = {F,cF}; %-Return figure handles
  511. if isempty(F), return, end %-Return if no ConMan win
  512. set(F,'Visible','off') %-Make window Invisible
  513. if strcmpi(Vis,'reset')
  514. set(findobj(F,'Tag','Done'),'UserData',-1)
  515. end
  516. return
  517. %------------------------------------------------------------------
  518. case 'on'
  519. %------------------------------------------------------------------
  520. %-Sort out arguments
  521. %--------------------------------------------------------------
  522. if nargin<8, OK2chg = 0; else OK2chg=varargin{8}; end
  523. if nargin<7, Mcstr = ''; else Mcstr=varargin{7}; end
  524. Mcstr = cellstr(Mcstr); if length(Mcstr)<2, Mcstr{2}=''; end
  525. if nargin<6, Prompt='Select contrast(s)'; else Prompt=varargin{6}; end
  526. if nargin<5, n=Inf; else n=varargin{5}; end
  527. if nargin<4, STATmode='T&F'; else STATmode=varargin{4}; end
  528. if nargin<3, error('insufficient arguments'), end
  529. SPM = varargin{3};
  530. xCon = SPM.xCon;
  531. xX = SPM.xX;
  532. %-Create/find ConMan window
  533. %--------------------------------------------------------------
  534. if isempty(F) %-Create ConMan win
  535. [F,H] = spm_conman('CreateFig');
  536. else %-Get handles
  537. H.hDesMtxAx = findobj(F,'Tag','DesMtxAx');
  538. H.hParEstAx = findobj(F,'Tag','ParEstAx');
  539. H.hConList = findobj(F,'Tag','ConList');
  540. H.hPrompt = findobj(F,'Tag','Prompt');
  541. H.hTFAf = findobj(F,'Tag','TFAf');
  542. H.hSTATmode = findobj(F,'Tag','STATmode');
  543. H.hStatLin = findobj(F,'Tag','StatusLine');
  544. H.hNew = findobj(F,'Tag','New');
  545. end
  546. varargout = {F,cF}; %-Return figure handles
  547. %-Store required parameters in UserData of various objects
  548. %--------------------------------------------------------------
  549. set(F, 'UserData',SPM)
  550. set(H.hStatLin, 'UserData',Mcstr)
  551. %-Initialise interface
  552. %--------------------------------------------------------------
  553. set(findobj(F,'Tag','Done'),'UserData',0) %-Init. Done UserData
  554. STAT = spm_conman('TFA',F,'',STATmode); %-Init. TFA buttons
  555. set(H.hPrompt,'String',Prompt,'UserData',n) %-Set prompt
  556. spm_conman('ImDesMtx',xX,H.hDesMtxAx) %-Depict DesMtx
  557. spm_conman('ImParEst',xX,H.hParEstAx) %-Parameter estimability
  558. spm_conman('ListCon',H.hConList,xCon,STAT,[]) %-List contrasts
  559. if OK2chg, tmp='on'; else tmp='off'; end %-OK to change xCon?
  560. set(H.hNew,'Enable',tmp) %-En/dis-able change UI
  561. %-**** if isempty(xCon), spm_conman(); end %-Go straight to DNewUI
  562. %-Popup figure, retaining CurrentFigure
  563. %--------------------------------------------------------------
  564. set(get(findobj(F,'Tag','DefineNew'),'UserData'),'Visible','off')
  565. %-Hide define UI
  566. figure(F) %-PopUp figure
  567. set(0,'CurrentFigure',cF) %-Return to prev. figure
  568. return
  569. otherwise
  570. error('Unrecognised ''Vis'' option')
  571. end
  572. %======================================================================
  573. case 'imdesmtx'
  574. %======================================================================
  575. % spm_conman('ImDesMtx',xX,h)
  576. h = varargin{3};
  577. %-Picture design matrix
  578. %------------------------------------------------------------------
  579. axes(h)
  580. if isfield(varargin{2},'nKX') && ~isempty(varargin{2}.nKX)
  581. hDesMtxIm = image((varargin{2}.nKX+1)*32);
  582. else
  583. hDesMtxIm = image(...
  584. (spm_DesMtx('sca',varargin{2}.xKXs.X,varargin{2}.name)+1)*32);
  585. end
  586. set(h,'YTick',[],'XTick',[]) %-No Tick marks
  587. set(h,'Tag','DesMtxAx','UserData',varargin{2}) %-Reset axis UserData after image
  588. xlabel('Design matrix')
  589. set(hDesMtxIm,'UserData',...
  590. struct('X',varargin{2}.xKXs.X,'Xnames',{varargin{2}.name}))
  591. set(hDesMtxIm,'ButtonDownFcn','spm_DesRep(''SurfDesMtx_CB'')')
  592. %======================================================================
  593. case 'imparest'
  594. %======================================================================
  595. % spm_conman('ImParEst',xX,h)
  596. xX = varargin{2};
  597. h = varargin{3};
  598. %-Picture design parameter estimability
  599. %------------------------------------------------------------------
  600. axes(h)
  601. est = spm_SpUtil('IsCon',xX.xKXs);
  602. nPar = length(est);
  603. hParEstIm = image((est+1)*32);
  604. set(h, 'XLim',[0,nPar]+.5,'XTick',[1:nPar-1]+.5,'XTickLabel','',...
  605. 'YLim',[0,1]+.5,'YDir','reverse','YTick',[],...
  606. 'Box','on','TickDir','in','XGrid','on','GridLineStyle','-');
  607. xlabel('parameter estimability')
  608. set(h,'Tag','ParEstAx') %-Reset 'Tag' after image cleared it
  609. set(hParEstIm,'UserData',struct('est',est,'Xnames',{xX.name}))
  610. set(hParEstIm,'ButtonDownFcn','spm_DesRep(''SurfEstIm_CB'')')
  611. %======================================================================
  612. case 'listcon'
  613. %======================================================================
  614. % spm_conman('ListCon',hConList,xCon,STAT,I)
  615. hConList = varargin{2};
  616. xCon = varargin{3};
  617. STAT = varargin{4};
  618. if nargin<5
  619. Q = get(hConList,'UserData');
  620. I = Q(get(hConList,'Value'));
  621. else
  622. I = varargin{5};
  623. end
  624. %-Sort out list, filtering by STAT, and display
  625. %------------------------------------------------------------------
  626. if isempty(xCon)
  627. Q = [];
  628. elseif isempty(STAT)
  629. Q = 1:length(xCon);
  630. else
  631. Q = find(strcmp({xCon(:).STAT},STAT));
  632. end
  633. q = find(ismember(Q,I));
  634. if ~isempty(Q)
  635. str = cell(0);
  636. for i=1:length(Q)
  637. str{i} = sprintf('%03d {%c} : %s',...
  638. Q(i),xCon(Q(i)).STAT,xCon(Q(i)).name);
  639. end
  640. FontAngle = 'Normal';
  641. FontWeight = 'Normal';
  642. Enable = 'on';
  643. else
  644. str = ['no',deblank([' ',STAT]),' contrasts defined'];
  645. FontAngle = 'Italic';
  646. FontWeight = 'Bold';
  647. Enable = 'off';
  648. end
  649. set(hConList,'String',str,...
  650. 'UserData',Q,...
  651. 'Value',q,...
  652. 'FontAngle',FontAngle,'FontWeight',FontWeight,...
  653. 'Enable',Enable)
  654. spm_conman('GraphCons',xCon,Q(q),get(hConList,'Parent'))
  655. spm_conman('StatusLine',get(hConList,'Parent'))
  656. %======================================================================
  657. case 'graphcons'
  658. %======================================================================
  659. % spm_conman('GraphCons',xCon,I,F)
  660. if nargin<2, error('insufficient arguments'), end
  661. xCon = varargin{2};
  662. if nargin<3, I=[1:length(xCon)]; else I=varargin{3}; end
  663. if nargin<4, F=[]; else F=varargin{4}; end
  664. if isempty(F), F=spm_figure('FindWin','ConMan'); end
  665. if isempty(F), error('can''t find ConMan win'), end
  666. cF = get(0,'CurrentFigure'); %-Save current figure
  667. set(0,'CurrentFigure',F); %-Make F current
  668. delete(findobj(F,'Tag','ConGrphAx'));
  669. %-Display contrasts
  670. %------------------------------------------------------------------
  671. if isempty(I)
  672. axes('Position',[0.65 (0.7 + .1*(1-0.9)) 0.3 .1*.9],...
  673. 'Tag','ConGrphAx','Visible','off')
  674. text(0.5,0.5,'no contrast(s)',...
  675. 'FontSize',spm('FontSize',8),...
  676. 'FontAngle','Italic',...
  677. 'HorizontalAlignment','Center',...
  678. 'VerticalAlignment','Middle')
  679. else
  680. nPar = size(xCon(1).c,1);
  681. xx = [repmat([0:nPar-1],2,1);repmat([1:nPar],2,1)];
  682. nCon = length(I);
  683. dy = 0.2/max(nCon,2);
  684. hConAx = axes('Position',[0.65 (0.70 + dy*.1) 0.30 dy*(nCon-.1)],...
  685. 'Tag','ConGrphAx','Visible','off');
  686. title('contrast(s)')
  687. htxt = get(hConAx,'title'); set(htxt,'Visible','on')
  688. for ii = nCon:-1:1
  689. i = abs(I(ii));
  690. axes('Position',[0.65 (0.7 + dy*(nCon-ii+.1)) 0.3 dy*.9])
  691. if xCon(i).STAT == 'T' && size(xCon(i).c,2)==1
  692. %-Single vector contrast for SPM{t} - bar
  693. yy = [zeros(1,nPar);repmat(xCon(i).c',2,1);zeros(1,nPar)];
  694. h = patch(xx,yy,[1,1,1]*.5);
  695. set(gca,'Tag','ConGrphAx',...
  696. 'Box','off','TickDir','out',...
  697. 'XTick',[],...
  698. 'XLim', [0,nPar],...
  699. 'YTick',[-1,0,+1],'YTickLabel','',...
  700. 'YLim', [min(xCon(i).c),max(xCon(i).c)] + ...
  701. [-1 +1] * max(abs(xCon(i).c))/10 )
  702. else
  703. %-F-contrast - image
  704. h = image((xCon(i).c'/max(abs(xCon(i).c(:)))+1)*32);
  705. set(gca,'Tag','ConGrphAx',...
  706. 'Box','on','TickDir','out',...
  707. 'XTick',[],...
  708. 'XLim', [0,nPar]+0.5,...
  709. 'YTick',[0:size(xCon(i).c,2)]+0.5,'YTickLabel','',...
  710. 'YLim', [0,size(xCon(i).c,2)]+0.5 )
  711. end
  712. if I(ii)>0, ylabel(num2str(i)), end
  713. set(h,'ButtonDownFcn','spm_DesRep(''SurfCon_CB'')',...
  714. 'UserData', struct( 'i', I(ii),...
  715. 'h', htxt,...
  716. 'xCon', xCon(i)))
  717. end
  718. end
  719. set(0,'CurrentFigure',cF) %-Reset CurrentFigure to previous figure
  720. %======================================================================
  721. case 'statusline'
  722. %======================================================================
  723. % spm_conman('StatusLine',F,str,col)
  724. if nargin<2, F = findobj(get(0,'Children'),'Flat','Tag','ConMan');
  725. else F = varargin{2}; end
  726. if nargin<3
  727. n = get(findobj(F,'Tag','Prompt'),'UserData');
  728. m = length(get(findobj(F,'Tag','ConList'),'Value'));
  729. str = sprintf('Selected %d contrast',m);
  730. if m~=1, str=[str,'s']; end
  731. Mcstr = get(findobj(F,'Tag','StatusLine'),'UserData');
  732. if m>1, str=[str,Mcstr{1}]; else str=[str,Mcstr{2}]; end
  733. if m==0
  734. if n<0
  735. str = [str,', press "Done" when finished.'];
  736. else
  737. str = [str,'.'];
  738. end
  739. else
  740. if n==1
  741. str = [str,', press "Done".'];
  742. else
  743. str = [str,', press "Done" when finished.'];
  744. end
  745. end
  746. else
  747. str = varargin{3};
  748. end
  749. if nargin<4, col='w'; else col=varargin{4}; end
  750. set(findobj(F,'Tag','StatusLine'),'String',str,'ForegroundColor',col)
  751. %======================================================================
  752. case 'done_cb'
  753. %======================================================================
  754. % spm_conman('Done_CB')
  755. F = gcbf;
  756. n = get(findobj(F,'Tag','Prompt'),'UserData');
  757. q = get(findobj(F,'Tag','ConList'),'Value');
  758. if n>0 && isempty(q) %-Contrast(s) required, but none selected
  759. if n==1, str = 'Select a contrast!';
  760. elseif isfinite(n), str = sprintf('Select %d contrasts!',n);
  761. else str = 'Select at least one contrast!';
  762. end
  763. elseif length(q)>abs(n) %-Too many contrasts selected
  764. if n<0, tstr='at most'; else tstr='only'; end
  765. if abs(n)==1, str = ['Select',tstr,' one contrast!'];
  766. else str = sprintf('Select %s %d contrasts!',tstr,abs(n));
  767. end
  768. elseif n>0 && isfinite(n) && length(q)<n
  769. if n==1, str = 'Select a contrast!';
  770. else str = sprintf('Select %d contrasts!',n);
  771. end
  772. else
  773. str = '';
  774. end
  775. if ~isempty(str) %-error: display error dialog box
  776. spm('Beep')
  777. msgbox(str,sprintf('%s: %s...',spm('Version'),mfilename),...
  778. 'error','modal')
  779. else %-OK, set Done UserData tag for handling
  780. set(findobj(F,'Tag','Done'),'UserData',1)
  781. end
  782. %======================================================================
  783. case 'conlist_cb'
  784. %======================================================================
  785. % spm_conman('ConList_CB')
  786. F = gcbf;
  787. hConList = gcbo;
  788. Q = get(hConList,'UserData');
  789. I = Q(get(hConList,'Value'));
  790. SPM = get(F,'UserData');
  791. xCon = SPM.xCon;
  792. spm_conman('GraphCons',xCon,I,F)
  793. spm_conman('StatusLine',get(hConList,'Parent'))
  794. if strcmp(get(F,'SelectionType'),'open'), spm_conman('Done_CB'), end
  795. %======================================================================
  796. case {'tfa','d_tf'}
  797. %======================================================================
  798. % STAT = spm_conman('TFA')
  799. % STAT = spm_conman('TFA',F,STAT)
  800. % STAT = spm_conman('TFA',F,STAT,STATmode)
  801. D = strcmpi(varargin{1},'d_tf'); %-Handling DefineNew UI?
  802. if nargin<2, F = gcbf; else F=varargin{2}; end
  803. if nargin<3 %-Called as CallBack of T or F RadioButton
  804. %------------------------------------------------------------------
  805. h = gcbo;
  806. if get(h,'Value')==0
  807. %-Was selected - don't allow unselection
  808. set(h,'Value',1)
  809. varargout={get(h,'UserData')};
  810. return
  811. else
  812. %-Get new STAT
  813. STAT = get(h,'UserData');
  814. end
  815. else
  816. STAT = varargin{3};
  817. end
  818. if ~(nargin<4) %-Called to set STAT & STATmode
  819. %------------------------------------------------------------------
  820. STATmode = varargin{4};
  821. b_set = 1;
  822. else
  823. STATmode = get(findobj(F,'Tag','STATmode'),'UserData');
  824. b_set = 0;
  825. end
  826. %-Check STATmode & STAT, set temporary STATmode & STAT indicies
  827. %------------------------------------------------------------------
  828. STATinfo = struct(... %-STAT info structure
  829. 'mode', { 'T', 'F', 'T|F', 'T&F'},...
  830. 'vSTAT', {{'T'},{'F'},{'T','F'},{'T','F',''}},...
  831. 'defSTAT', { 'T', 'F', 'T', ''},...
  832. 'Enable', { {'on', 'off','off'},...
  833. {'off','on' ,'off'},...
  834. {'on', 'on', 'off'},...
  835. {'on', 'on', 'on' }} );
  836. i = find(strcmp(STATmode,{STATinfo.mode})); %-STATmode index
  837. if isempty(i), error('unknown STATmode'), end %-Check STATmode valid
  838. if D && i==4, i=3; end %-Treat 'T&F' as 'T|F'?
  839. if isempty(STAT), STAT=STATinfo(i).defSTAT; end %-Set STAT as default(?)
  840. j = find(strcmp(STAT,{'T','F',''})); %-STAT index
  841. if isempty(j), error('unknown STAT'); end %-Check known STAT
  842. if ~any(strcmp(STAT,STATinfo(i).vSTAT)) %-Check STAT is
  843. error('Invalid STAT for this STATmode') % valid for
  844. end % this STATmode
  845. %-Set STAT buttons (& Dis/Enable according to STATmode if b_setEnable)
  846. %------------------------------------------------------------------
  847. if ~D, Tag='TFA'; else Tag='D_TF'; end
  848. H = flipud(findobj(F,'Tag',Tag));
  849. set(H(j), 'Value',1)
  850. set(H(setdiff([1:length(H)],j)),'Value',0)
  851. if b_set
  852. %-Set RadioButton 'Enable' & store STATmode
  853. set(findobj(F,'Tag','STATmode'),'UserData',STATmode)
  854. for k=1:length(H), set(H(k),'Enable',STATinfo(i).Enable{k}), end
  855. end
  856. if ~D %-Additional UI setup for main contrast manager
  857. %------------------------------------------------------------------
  858. %-Reset ConList for new STAT if callback for TFA button
  859. %--------------------------------------------------------------
  860. if nargin<3
  861. SPM = get(F,'UserData');
  862. xCon = SPM.xCon;
  863. spm_conman('ListCon',findobj(F,'Tag','ConList'),xCon,STAT)
  864. end
  865. else %-Additional UI setup for DNew contrast definition interface
  866. %------------------------------------------------------------------
  867. %-Get handles of control objects
  868. %--------------------------------------------------------------
  869. hD_ConMtx = findobj(F,'Tag','D_ConMtx');
  870. hD_X1cols = findobj(F,'Tag','D_X1cols');
  871. hD_ConErrs = findobj(F,'Tag','D_ConErrs');
  872. hD_ConInfo = findobj(F,'Tag','D_ConInfo');
  873. HD_Ttxt = findobj(F,'Tag','D_Ttxt');
  874. HD_Ftxt = findobj(F,'Tag','D_Ftxt');
  875. %-Set interface for new STAT
  876. %--------------------------------------------------------------
  877. set(hD_ConMtx,'String',{},'UserData',[]) %-Clear ConMtx box
  878. set(hD_X1cols,'String','') %-Clear X1cols box
  879. set([hD_ConErrs,hD_ConInfo],'String',{},'Value',[]) %-Clear parsing boxes
  880. spm_conman('GraphCons',[],[],F) %-Clear contrast plot
  881. spm_conman('D_Status',F) %-Set StatusLine
  882. switch STAT
  883. case 'T'
  884. set(hD_ConMtx,'Max',1)
  885. set(HD_Ttxt,'Visible','on')
  886. set([hD_X1cols;HD_Ftxt],'Visible','off')
  887. case 'F'
  888. set(hD_ConMtx,'Max',2)
  889. set(HD_Ttxt,'Visible','off')
  890. set([hD_X1cols;HD_Ftxt],'Visible','on')
  891. otherwise
  892. error('illegal case')
  893. end
  894. end
  895. %-Return STAT
  896. %------------------------------------------------------------------
  897. varargout = {STAT};
  898. %======================================================================
  899. case 'fconmenu_cb'
  900. %======================================================================
  901. % spm_conman('FConMenu_CB')
  902. if strcmp(get(findobj(gcbf,'Tag','New'),'Enable'),'off')
  903. set(findobj(gcbo,'Tag','CM_New'),'Enable','off')
  904. set(findobj(gcbo,'Tag','CM_Ren'),'Enable','off')
  905. else
  906. set(findobj(gcbo,'Tag','CM_New'),'Enable','on')
  907. if length(get(findobj(gcbf,'Tag','ConList'),'Value'))==1
  908. set(findobj(gcbo,'Tag','CM_Ren'),'Enable','on')
  909. else
  910. set(findobj(gcbo,'Tag','CM_Ren'),'Enable','off')
  911. end
  912. end
  913. %======================================================================
  914. case 'rename_cb'
  915. %======================================================================
  916. % spm_conman('Rename_CB')
  917. F = gcbf;
  918. hConList = findobj(F,'Tag','ConList');
  919. Q = get(hConList,'UserData');
  920. i = get(hConList,'Value');
  921. %-Make sure there's only one selected contrast
  922. %------------------------------------------------------------------
  923. if length(i)~=1
  924. msgbox('Can only rename a single contrast!',...
  925. sprintf('%s: %s...',spm('Version'),mfilename),...
  926. 'error','modal')
  927. return
  928. end
  929. %-Get contrast structure array and indicies of current contrast
  930. %------------------------------------------------------------------
  931. SPM = get(F,'UserData');
  932. xCon = SPM.xCon;
  933. I = Q(i);
  934. %-Get new name
  935. %------------------------------------------------------------------
  936. str = sprintf('Enter new name for contrast %d (currently "%s"):',I,xCon(I).name);
  937. nname = inputdlg(str,'SPM: Rename contrast',1,{xCon(I).name},'off');
  938. if isempty(nname), return, end
  939. %-Change name in ConList
  940. %------------------------------------------------------------------
  941. tmp = get(hConList,'String');
  942. tmp{i} = strrep(tmp{i},xCon(I).name,nname{1});
  943. set(hConList,'String',tmp)
  944. %-Change name in contrast structure
  945. %------------------------------------------------------------------
  946. xCon(I).name = nname{1};
  947. SPM.xCon = xCon;
  948. set(F,'UserData',SPM)
  949. %======================================================================
  950. case 'parsecon' %-Parse (cell)string into contrast
  951. %======================================================================
  952. % [c,I,emsg,imsg,msg] = spm_conman('ParseCon',cstr,X,STAT)
  953. % X is raw DesMtx or space structure
  954. %-Sort out parameters
  955. %------------------------------------------------------------------
  956. if nargin<4, STAT='F'; else STAT=varargin{4}; end
  957. cstr = varargin{2};
  958. X = varargin{3};
  959. p = spm_SpUtil('size',X,2);
  960. %-Preliminary parsing of contrast string (cstr) into cellstr
  961. %------------------------------------------------------------------
  962. if isempty(cstr)
  963. varargout = {[],0,{' <- !empty input'},{},{}};
  964. return
  965. elseif iscell(cstr)
  966. if numel(cstr)~=1, cstr=cstr(:); end
  967. c = cstr;
  968. elseif ischar(cstr)
  969. cstr = cellstr(cstr);
  970. c = cstr;
  971. elseif isnumeric(cstr)
  972. if ndims(cstr)>2, error('matrices only!'), end
  973. c = num2cell(cstr,2);
  974. cstr = cell(size(c));
  975. for i=1:numel(c), cstr{i}=num2str(c{i}); end
  976. else
  977. error('contrast input must be string or number')
  978. end
  979. %-Evaluate individual lines of contrast matrix input
  980. %------------------------------------------------------------------
  981. I = zeros(size(c,1),1);
  982. msg = cell(size(c)); [msg{:}] = deal(' (OK)');
  983. for i=1:size(c,1)
  984. if ischar(c{i})
  985. c{i} = evalin('base',['[',c{i},']'],'''!''');
  986. end
  987. if ischar(c{i})
  988. msg{i} = '!evaluation error';
  989. else
  990. if isempty(c{i})
  991. msg{i}=' (empty line - ignored)';
  992. elseif all(c{i}(:)==0)
  993. if size(c{i},1)==1, str='vector'; else str='matrix'; end
  994. c{i}=[]; msg{i}=[' (zero ',str,' - ignored)'];
  995. elseif STAT=='T' && size(c{i},1)>1
  996. c{i}='!'; msg{i}='!vector required';
  997. elseif size(c{i},2)>p
  998. c{i}='!'; msg{i}=sprintf('!too long - only %d prams',p);
  999. else
  1000. if size(c{i},2)<p
  1001. tmp = p-size(c{i},2);
  1002. c{i}=[c{i}, zeros(size(c{i},1),tmp)];
  1003. if size(c{i},1)>1, str=' column'; else str=''; end
  1004. if tmp>1, str=[str,'s']; end
  1005. msg{i} = sprintf(' (right padded with %d zero%s)',tmp,str);
  1006. end
  1007. if ~spm_SpUtil('allCon',X,c{i}')
  1008. c{i}='!'; msg{i}='!invalid contrast';
  1009. end
  1010. end
  1011. end
  1012. I(i)=~ischar(c{i});
  1013. end
  1014. %-Construct contrast matrix, validity indicator, and collate parsing messages
  1015. %------------------------------------------------------------------
  1016. c = cat(1,c{find(I)});
  1017. msg = [char(cstr), repmat(' <- ',size(msg,1),1), char(msg)];
  1018. emsg = msg(find(~I),:);
  1019. imsg = msg(find( I),:);
  1020. if all(I) && STAT=='T' && size(c,1)>1 %-Check for vector t-contrasts!
  1021. I=zeros(size(I)); emsg={'!vector required'}; imsg={};
  1022. end
  1023. %-Return arguments
  1024. %------------------------------------------------------------------
  1025. varargout = {c',I,emsg,imsg,msg};
  1026. %======================================================================
  1027. case 'parseistr' %-Parse index string
  1028. %======================================================================
  1029. % [iX0,I,emsg,imsg] = spm_conman('ParseIStr',str,max)
  1030. % str should be a string (row)vector
  1031. %-Sort out parameters
  1032. %------------------------------------------------------------------
  1033. str = varargin{2};
  1034. mx = varargin{3};
  1035. %-Process input string
  1036. %------------------------------------------------------------------
  1037. I = evalin('base',['[',str,']'],'''!''');
  1038. if ischar(I)
  1039. varargout = {'!',0,[str,' <- !evaluation error'],''};
  1040. return
  1041. end
  1042. %-Construct list of valid indicies
  1043. %------------------------------------------------------------------
  1044. ok = ismember(I(:)', 1:mx);
  1045. iX0 = I(ok);
  1046. %-Construct diagnostic info messages
  1047. %------------------------------------------------------------------
  1048. str = {}; msg={};
  1049. if any(ok)
  1050. str = [str; num2str(I(ok))];
  1051. msg = [msg; ' <- (OK)'];
  1052. end
  1053. tmp = ( I<1 | I>mx ); %-Out of range
  1054. if any(tmp)
  1055. str = [str; num2str(I(tmp))];
  1056. msg = [msg; sprintf(' <- (ignored - not in [1:%d]',mx)];
  1057. end
  1058. tmp = ( ~tmp & ~ok ); %-Non integer in range
  1059. if any(tmp)
  1060. str = [str; num2str(I(tmp))];
  1061. msg = [msg; ' <- (ignored - non-integer)'];
  1062. end
  1063. %-Return arguments
  1064. %------------------------------------------------------------------
  1065. varargout = {iX0,1,'',cellstr([char(str),char(msg)])};
  1066. %======================================================================
  1067. case 'reset_cb'
  1068. %======================================================================
  1069. % spm_conman('Reset_CB')
  1070. hConList = findobj(gcbf,'Tag','ConList');
  1071. SPM = get(gcf,'UserData');
  1072. xCon = SPM.xCon;
  1073. STAT = get(findobj(gcbf,'Tag','TFA','Value',1),'UserData');
  1074. spm_conman('ListCon',hConList,xCon,STAT,[])
  1075. %======================================================================
  1076. case 'd_setup_cb'
  1077. %======================================================================
  1078. % spm_conman('D_Setup_CB')
  1079. F = gcbf;
  1080. STAT = get(findobj(F,'Tag','TFA','Value',1),'UserData');
  1081. STATmode = get(findobj(F,'Tag','STATmode'),'UserData');
  1082. set(F,'UIContextMenu',[]) %-Disable Fig ContextMenu
  1083. H = get(findobj(F,'Tag','DefineNew'),'UserData'); %-Get define UI handles
  1084. set(findobj(H,'flat','Tag','D_name'),'String','') %-Clear name
  1085. %set(findobj(H,'flat','Tag','D_ConMtx'),'UserData',[]) %-Clear con definition
  1086. set(H,'Visible','on') %-Show UI
  1087. SPM = get(F, 'UserData');
  1088. spm_conman('D_TF',F,STAT,STATmode); %-Setup rest of define UI
  1089. %======================================================================
  1090. case {'d_conmtx_cb','d_x1cols_cb'}
  1091. %======================================================================
  1092. % spm_conman('D_ConMtx_CB')
  1093. % spm_conman('D_X1cols_CB')
  1094. fcn = find(strcmpi(varargin{1},{'d_conmtx_cb','d_x1cols_cb'}));
  1095. F = findobj('Tag', 'ConMan');
  1096. hD_ConMtx = findobj(F,'Tag','D_ConMtx');
  1097. hD_X1cols = findobj(F,'Tag','D_X1cols');
  1098. if strcmpi(get(hD_ConMtx, 'Enable'), 'on')
  1099. if fcn == 1
  1100. str = get(hD_ConMtx,'String');
  1101. elseif fcn == 2
  1102. str = get(hD_X1cols,'String');
  1103. else
  1104. % This shouldn't happen
  1105. end
  1106. else
  1107. % This shouldn't happen
  1108. end
  1109. %-Extract info from holding objects
  1110. %------------------------------------------------------------------
  1111. xX = get(findobj(F,'Tag','DesMtxAx'),'UserData');
  1112. STAT = get(findobj(F,'Tag','D_TF','Value',1),'UserData');
  1113. if fcn==1 %-Parse string from ConMtx widget
  1114. %------------------------------------------------------------------
  1115. set(hD_X1cols,'String','')
  1116. [c,I,emsg,imsg] = spm_conman('ParseCon',str,xX.xKXs,STAT);
  1117. if all(I)
  1118. DxCon = spm_FcUtil('Set','',STAT,'c',c,xX.xKXs);
  1119. else
  1120. DxCon = [];
  1121. end
  1122. elseif fcn==2 %-Process column indicies from X1cols widget
  1123. %------------------------------------------------------------------
  1124. set(hD_ConMtx,'String','')
  1125. nPar = spm_SpUtil('size',xX.xKXs,2);
  1126. [iX0,I,emsg,imsg] = spm_conman('ParseIStr',str,nPar);
  1127. if I
  1128. try %-try-catch block for any errors in spm_FcUtil!
  1129. DxCon = spm_FcUtil('Set','',STAT,'iX0',iX0,xX.xKXs);
  1130. if STAT=='T' && size(DxCon.c,2)>1
  1131. I = 0; emsg = {'! t-contrasts must be vectors'};
  1132. end
  1133. catch
  1134. I = 0;
  1135. emsg = lasterr;
  1136. end
  1137. end
  1138. end
  1139. %-Define the contrast or report errors...
  1140. %------------------------------------------------------------------
  1141. set(findobj(F,'Tag','D_ConErrs'),'String',emsg,'Value',[])
  1142. set(findobj(F,'Tag','D_ConInfo'),'String',imsg,'Value',[])
  1143. if all(I)
  1144. set(hD_ConMtx,'UserData',DxCon); %-Store contrast
  1145. spm_conman('GraphCons',DxCon,-1,F) %-Depict contrast
  1146. else
  1147. set(hD_ConMtx,'UserData',[]); %-Clear contrast store
  1148. spm_conman('GraphCons',[],[],F) %-Clear contrast plot
  1149. end
  1150. spm_conman('D_Status',F) %-Set StatusLine
  1151. %======================================================================
  1152. case 'd_reset_cb'
  1153. %======================================================================
  1154. % spm_conman('D_Reset_CB')
  1155. STAT = get(findobj(gcbf,'Tag','TFA','Value',1),'UserData');
  1156. set(findobj(gcbf,'Tag','D_name'),'String','') %-Clear name
  1157. set(findobj(gcbf,'Tag','D_ConMtx'),'UserData',[]) %-Contrast definition
  1158. spm_conman('D_TF',gcbf,STAT); %-Setup rest of define UI
  1159. %======================================================================
  1160. case 'd_cancel_cb'
  1161. %======================================================================
  1162. % spm_conman('D_Cancel_CB')
  1163. set(get(findobj(gcbf,'Tag','DefineNew'),'UserData'),'Visible','off')
  1164. set(gcbf,'UIContextMenu',findobj(gcbf,'Tag','ConMan_ConMen'))
  1165. spm_conman('StatusLine')
  1166. %======================================================================
  1167. case 'd_ok_cb'
  1168. %======================================================================
  1169. % spm_conman('D_OK_CB')
  1170. F = gcbf;
  1171. name = get(findobj(F,'Tag','D_name'),'String');
  1172. DxCon = get(findobj(F,'Tag','D_ConMtx'),'UserData');
  1173. STAT = get(findobj(F,'Tag','D_TF','Value',1),'UserData');
  1174. dNam = ~isempty(name);
  1175. dCon = ~isempty(DxCon);
  1176. if ~(dNam && dCon)
  1177. spm('Beep')
  1178. str = { 'contrast name not defined!','',...
  1179. 'no valid contrast defined!',''};
  1180. msgbox(str([dNam+1,dCon+3]),...
  1181. sprintf('%s: %s...',spm('Version'),mfilename),...
  1182. 'error','modal')
  1183. return
  1184. end
  1185. %-Append new contrast to xCon structure of ConMan figure 'UserData'
  1186. %------------------------------------------------------------------
  1187. DxCon.name = name;
  1188. if ~strcmp(DxCon.STAT,STAT), error('STAT & DxCon.STAT mismatch!'), end
  1189. SPM = get(F,'UserData');
  1190. xCon = SPM.xCon;
  1191. % Due to an earlier bug in SPM, a spurious field
  1192. % PSTAT may have been created. Remove this if it exists.
  1193. if isfield(xCon,'PSTAT')
  1194. xCon=rmfield(xCon,'PSTAT');
  1195. end
  1196. if isempty(xCon)
  1197. xCon = DxCon;
  1198. else
  1199. xCon = [xCon, DxCon];
  1200. end
  1201. SPM.xCon = xCon;
  1202. set(F,'UserData',SPM);
  1203. %-Redisplay the new list of contrasts, with the new one selected
  1204. %------------------------------------------------------------------
  1205. hConList = findobj(F,'Tag','ConList');
  1206. I = length(xCon);
  1207. %-Use this code to add the new contrast to a multiple selection, if allowed
  1208. % Q = get(hConList,'UserData');
  1209. % I = Q(get(hConList,'Value'));
  1210. % n = get(findobj(F,'Tag','Prompt'),'UserData');
  1211. % if abs(n)>1, I=[I,length(xCon)]; else, I=length(xCon); end
  1212. spm_conman('TFA',F,xCon(end).STAT); %-Set STAT
  1213. spm_conman('ListCon',hConList,xCon,xCon(end).STAT,I) %-ListCon
  1214. %-Hide the DefineNew UI
  1215. %------------------------------------------------------------------
  1216. set(get(findobj(gcbf,'Tag','DefineNew'),'UserData'),'Visible','off')
  1217. set(gcbf,'UIContextMenu',findobj(gcbf,'Tag','ConMan_ConMen'))
  1218. %======================================================================
  1219. case 'd_status'
  1220. %======================================================================
  1221. % spm_conman('D_Status',F)
  1222. if nargin<2, F=gcbf; else F=varargin{2}; end
  1223. str = {' not',''};
  1224. dNam = ~isempty(get(findobj(F,'Tag','D_name'),'String'));
  1225. dCon = ~isempty(get(findobj(F,'Tag','D_ConMtx'),'UserData'));
  1226. if dNam && dCon, ok='on'; col='g'; else ok='off'; col='w'; end
  1227. spm_conman('StatusLine',F,...
  1228. sprintf('name%s defined, contrast%s defined',str{dNam+1},str{dCon+1}),...
  1229. col)
  1230. %set(findobj(F,'Tag','D_OK'),'Enable',ok) %-Enable "OK" button?
  1231. %======================================================================
  1232. case 'createfig'
  1233. %======================================================================
  1234. % [F,H] = spm_conman('CreateFig')
  1235. % Handle Structure - H.{hConList,hDesMtxAx,hPrompt,hSTATmode,hStatLin,hNew}
  1236. cF = get(0,'CurrentFigure'); %-Save current figure
  1237. %-Create window, compute scaling for screen size
  1238. %------------------------------------------------------------------
  1239. WS = spm('WinScale'); %-Window scaling factors
  1240. FS = spm('FontSizes'); %-Scaled font sizes
  1241. PF = spm_platform('fonts'); %-Font names (for this platform)
  1242. S0 = spm('WinSize','0',1); %-Screen size (of the current monitor)
  1243. F = figure('IntegerHandle','off',...
  1244. 'Tag','ConMan',...
  1245. 'Name','SPM contrast manager','NumberTitle','off',...
  1246. 'Position',[S0(1)+S0(3)/2,S0(2)+S0(4)/2,0,0] + [-250,-200,500,400].*WS,...
  1247. 'Resize','off',...
  1248. 'Color',[1 1 1]*.7,...
  1249. 'MenuBar','none',...
  1250. 'DefaultTextColor','k',...
  1251. 'DefaultTextFontName',PF.helvetica,...
  1252. 'DefaultTextFontSize',FS(10),...
  1253. 'DefaultAxesFontName',PF.helvetica,...
  1254. 'DefaultUicontrolBackgroundColor',[1 1 1]*.7,...
  1255. 'DefaultUicontrolFontName',PF.helvetica,...
  1256. 'DefaultUicontrolFontSize',FS(10),...
  1257. 'DefaultUicontrolInterruptible','on',...
  1258. 'Colormap',gray(64),...
  1259. 'Renderer',spm_get_defaults('renderer'),...
  1260. 'Visible','off');
  1261. %-Draw GUI objects
  1262. %------------------------------------------------------------------
  1263. hPrompt = uicontrol(F,'Style','Text','Tag','Prompt','UserData',[],...
  1264. 'String','<Prompt not set yet>',...
  1265. 'FontName',PF.times,...
  1266. 'FontWeight','Bold',...
  1267. 'FontAngle','Italic',...
  1268. 'FontSize',FS(16),...
  1269. 'ForegroundColor','k',...
  1270. 'BackgroundColor',[1,1,1]*.7,...
  1271. 'HorizontalAlignment','Center',...
  1272. 'Position',[020 370 280 025].*WS);
  1273. % ----------------
  1274. %-T/F/all buttons...
  1275. hSTATmode = uicontrol(F,'Style','Frame','Tag','STATmode',...
  1276. 'Position',[040 340 260 028].*WS);
  1277. uicontrol(F,'Style','Text','String','show',...
  1278. 'FontName',PF.times,'FontAngle','Italic','FontSize',FS(8),...
  1279. 'ForegroundColor','w',...
  1280. 'Position',[045 365 030 010].*WS);
  1281. hT = uicontrol(F,'Style','RadioButton','String','t-contrasts','Tag','TFA',...
  1282. 'ToolTipString','...to show only contrasts for SPM{t}',...
  1283. 'FontSize',FS(9),...
  1284. 'ForegroundColor','k',...
  1285. 'UserData','T',...
  1286. 'Position',[044 343 105 020].*WS);
  1287. hF = uicontrol(F,'Style','RadioButton','String','F-contrasts','Tag','TFA',...
  1288. 'ToolTipString','...to show only contrasts for SPM{F}',...
  1289. 'FontSize',FS(9),...
  1290. 'ForegroundColor','k',...
  1291. 'UserData','F',...
  1292. 'Position',[149 343 105 020].*WS);
  1293. hA = uicontrol(F,'Style','RadioButton','String','all','Tag','TFA',...
  1294. 'ToolTipString','...to show all defined contrasts',...
  1295. 'FontSize',FS(9),...
  1296. 'ForegroundColor','k',...
  1297. 'UserData','',...
  1298. 'Position',[254 343 041 020].*WS);
  1299. set([hT,hF,hA],'CallBack','spm_conman(''TFA'');',...
  1300. 'Interruptible','off','BusyAction','Queue')
  1301. % ----------------
  1302. %-Contrast list...
  1303. uicontrol(F,'Style','Text','Tag','ConListHdr',...
  1304. 'String','### {type} : name',...
  1305. 'FontSize',FS(8),'FontAngle','Italic',...
  1306. 'HorizontalAlignment','Left',...
  1307. 'BackgroundColor','w',...
  1308. 'Position',[042 320 256 016].*WS);
  1309. hh = uicontextmenu('Tag','ConMan_ConMenu');
  1310. uimenu(hh,'Label','Rename selected contrast...',...
  1311. 'Tag','CM_Ren',...
  1312. 'CallBack', 'spm_conman(''Rename_CB'')',...
  1313. 'Interruptible','off','BusyAction','Cancel');
  1314. set(hh,'CallBack','spm_conman(''FConMenu_CB'')',...
  1315. 'Interruptible','off','BusyAction','Cancel');
  1316. hConList = uicontrol(F,'Style','ListBox','Tag','ConList',...
  1317. 'ToolTipString',['Select contrast(s) - drag/shift-click',...
  1318. '/ctrl-click to select multiple contrasts'],...
  1319. 'String',{'list','not','set','yet'},...
  1320. 'Max',2,...
  1321. 'CallBack','spm_conman(''ConList_CB'')',...
  1322. 'UIContextMenu',hh,...
  1323. 'Interruptible','off','BusyAction','Queue',...
  1324. 'BackgroundColor','w',...
  1325. 'Position',[040 080 260 240].*WS);
  1326. % ----------------
  1327. %-Control buttons & status area...
  1328. hNew = uicontrol(F,'Style','Pushbutton','String','Define new contrast...',...
  1329. 'Tag','New',...
  1330. 'ToolTipString','define new contrast',...
  1331. 'ForegroundColor','b',...
  1332. 'Callback','spm_conman(''D_Setup_CB'')',...
  1333. 'Enable','on',...
  1334. 'Position',[040 050 150 022].*WS);
  1335. uicontrol(F,'Style','Pushbutton','String','Reset',...
  1336. 'ToolTipString','reset selection',...
  1337. 'ForegroundColor','r',...
  1338. 'Callback','spm_conman(''Reset_CB'')',...
  1339. 'Position',[195 050 050 022].*WS);
  1340. uicontrol(F,'Style','Pushbutton','String','Done',...
  1341. 'ToolTipString','done - press when selected contrast(s)',...
  1342. 'ForegroundColor','m',...
  1343. 'Tag','Done','UserData',1,...
  1344. 'Callback','spm_conman(''Done_CB'')',...
  1345. 'Interruptible','off','BusyAction','Cancel',...
  1346. 'Position',[250 050 050 022].*WS);
  1347. uicontrol(F,'Style','Frame','Tag','StatusArea',...
  1348. 'Position',[010 010 480 030].*WS);
  1349. hStatLin = uicontrol(F,'Style','Text','Tag','StatusLine',...
  1350. 'String','<Not set yet>',...
  1351. 'FontAngle','Italic',...
  1352. 'HorizontalAlignment','Center',...
  1353. 'ForegroundColor','w',...
  1354. 'Position',[020 015 430 020].*WS);
  1355. % ----------------
  1356. %-Axes for design matrix and parameter estimability...
  1357. hDesMtxAx = axes('Parent',F,'Tag','DesMtxAx',...
  1358. 'Position',[0.65 0.30 0.30 0.40],...
  1359. 'Color','w',...
  1360. 'Box','on','XTick',[],'YTick',[]);
  1361. hParEstAx = axes('Parent',F,'Tag','ParEstAx',...
  1362. 'Position',[0.65 0.18 0.30 0.05],...
  1363. 'Color','w',...
  1364. 'Box','on','XTick',[],'YTick',[]);
  1365. % ----------------
  1366. %-Figure UICOntextMenu
  1367. h = uicontextmenu('Tag','ConMan_ConMen');
  1368. set(F,'UIContextMenu',h)
  1369. uimenu(h,'Label','Define new contrast...',...
  1370. 'Tag','CM_New',...
  1371. 'CallBack','spm_conman(''D_Setup_CB'')',...
  1372. 'Interruptible','off','BusyAction','Cancel');
  1373. uimenu(h,'Label','Rename selected contrast...',...
  1374. 'Tag','CM_Ren',...
  1375. 'CallBack','spm_conman(''Rename_CB'')',...
  1376. 'Interruptible','off','BusyAction','Cancel');
  1377. uimenu(h,'Label','Reset','Separator','on',...
  1378. 'CallBack','spm_conman(''Reset_CB'')',...
  1379. 'Interruptible','off','BusyAction','Cancel');
  1380. uimenu(h,'Label','Done',...
  1381. 'CallBack','spm_conman(''Done_CB'')',...
  1382. 'Interruptible','off','BusyAction','Cancel');
  1383. uimenu(h,'Label','crash out','Separator','on',...
  1384. 'CallBack','spm_conman(''Initialise'',''reset'');',...
  1385. 'Interruptible','off','BusyAction','Cancel');
  1386. set(h,'CallBack','spm_conman(''FConMenu_CB'')',...
  1387. 'Interruptible','off','BusyAction','Cancel');
  1388. %-Draw contrast definition GUI
  1389. %------------------------------------------------------------------
  1390. H = []; %-Save handles for visibility switching
  1391. h = uicontrol(F,'Style','Frame','Tag','DefineNew',...
  1392. 'Position',[010 045 300 350].*WS);
  1393. H = [H,h];
  1394. h = uicontrol(F,'Style','Text','Tag','D_Prompt','UserData',[],...
  1395. 'String','define contrast...',...
  1396. 'FontName',PF.times,...
  1397. 'FontWeight','Bold',...
  1398. 'FontAngle','Italic',...
  1399. 'FontSize',FS(14),...
  1400. 'ForegroundColor','b',...
  1401. 'HorizontalAlignment','Center',...
  1402. 'Position',[020 360 280 030].*WS);
  1403. H = [H,h];
  1404. % ----------------
  1405. %-name
  1406. h = uicontrol(F,'Style','Frame','Position',[020 335 280 033].*WS);
  1407. H = [H,h];
  1408. h = uicontrol(F,'Style','Text','String','name',...
  1409. 'FontSize',FS(10),...
  1410. 'FontAngle','Italic',...
  1411. 'ForegroundColor','w',...
  1412. 'HorizontalAlignment','Center',...
  1413. 'Position',[025 355 045 020].*WS);
  1414. H = [H,h];
  1415. h = uicontrol(F,'Style','Edit','Tag','D_name',...
  1416. 'ToolTipString','enter name for contrast',...
  1417. 'HorizontalAlignment','Left',...
  1418. 'BackgroundColor',COLOUR,...
  1419. 'Callback','spm_conman(''D_Status'')','Interruptible','off',...
  1420. 'Position',[080 340 215 022].*WS);
  1421. H = [H,h];
  1422. % ----------------
  1423. %-type
  1424. h = uicontrol(F,'Style','Frame','Position',[020 295 280 033].*WS);
  1425. H = [H,h];
  1426. h = uicontrol(F,'Style','Text','String','type',...
  1427. 'FontSize',FS(10),...
  1428. 'FontAngle','Italic',...
  1429. 'ForegroundColor','w',...
  1430. 'HorizontalAlignment','Center',...
  1431. 'Position',[025 315 040 020].*WS);
  1432. H = [H,h];
  1433. hDT = uicontrol(F,'Style','RadioButton','String','t-contrast','Tag','D_TF',...
  1434. 'ToolTipString','...to define contrast for SPM{t}',...
  1435. 'FontSize',FS(9),...
  1436. 'ForegroundColor','k',...
  1437. 'UserData','T',...
  1438. 'Position',[080 300 105 022].*WS);
  1439. hDF = uicontrol(F,'Style','RadioButton','String','F-contrast','Tag','D_TF',...
  1440. 'ToolTipString','...to define contrast for SPM{F}',...
  1441. 'FontSize',FS(9),...
  1442. 'ForegroundColor','k',...
  1443. 'UserData','F',...
  1444. 'Position',[190 300 105 022].*WS);
  1445. set([hDT,hDF],'CallBack','spm_conman(''D_TF'');',...
  1446. 'Interruptible','off','BusyAction','Queue')
  1447. H = [H,hDT,hDF];
  1448. % ----------------
  1449. %-contrast
  1450. h = uicontrol(F,'Style','Frame','Position',[020 080 280 208].*WS);
  1451. H = [H,h];
  1452. h = uicontrol(F,'Style','Text','String','contrast',...
  1453. 'FontSize',FS(10),...
  1454. 'FontAngle','Italic',...
  1455. 'ForegroundColor','w',...
  1456. 'HorizontalAlignment','Center',...
  1457. 'Position',[025 275 055 020].*WS);
  1458. H = [H,h];
  1459. h = uicontrol(F,'Style','Text','String','contrast',...
  1460. 'FontSize',FS(6),...
  1461. 'HorizontalAlignment','Right',...
  1462. 'Position',[030 255 045 008].*WS);
  1463. H = [H,h];
  1464. h = uicontrol(F,'Style','Text','String','weights',...
  1465. 'FontSize',FS(6),...
  1466. 'HorizontalAlignment','Right',...
  1467. 'Position',[030 245 045 008].*WS);
  1468. H = [H,h];
  1469. h = uicontrol(F,'Style','Text','String','vector','Tag','D_Ttxt',...
  1470. 'FontSize',FS(6),...
  1471. 'HorizontalAlignment','Right',...
  1472. 'Position',[030 235 045 008].*WS);
  1473. H = [H,h];
  1474. h = uicontrol(F,'Style','Text','String','matrix','Tag','D_Ftxt',...
  1475. 'FontSize',FS(6),...
  1476. 'HorizontalAlignment','Right',...
  1477. 'Position',[030 235 045 008].*WS);
  1478. H = [H,h];
  1479. h = uicontrol(F,'Style','Edit','Tag','D_ConMtx',...
  1480. 'ToolTipString','enter contrast',...
  1481. 'HorizontalAlignment','Left',...
  1482. 'BackgroundColor',COLOUR,...
  1483. 'Max',2,...
  1484. 'CallBack','spm_conman(''D_ConMtx_CB'')',...
  1485. 'Interruptible','off','BusyAction','Queue',...
  1486. 'UserData',[],...
  1487. 'Position',[080 200 215 082].*WS);
  1488. H = [H,h];
  1489. h = uicontrol(F,'Style','Text','String','or','Tag','D_Ftxt',...
  1490. 'FontAngle','Italic',...
  1491. 'FontSize',FS(6),...
  1492. 'HorizontalAlignment','Left',...
  1493. 'Position',[025 205 030 008].*WS);
  1494. H = [H,h];
  1495. h = uicontrol(F,'Style','Text','String','columns for','Tag','D_Ftxt',...
  1496. 'FontSize',FS(6),...
  1497. 'HorizontalAlignment','Right',...
  1498. 'Position',[022 190 070 008].*WS);
  1499. H = [H,h];
  1500. h = uicontrol(F,'Style','Text','String','reduced design','Tag','D_Ftxt',...
  1501. 'FontSize',FS(6),...
  1502. 'HorizontalAlignment','Right',...
  1503. 'Position',[022 180 070 008].*WS);
  1504. H = [H,h];
  1505. h = uicontrol(F,'Style','Edit','Tag','D_X1cols',...
  1506. 'ToolTipString',...
  1507. 'enter column indicies of reduced design matrix X0',...
  1508. 'HorizontalAlignment','Left',...
  1509. 'BackgroundColor',COLOUR,...
  1510. 'CallBack','spm_conman(''D_X1cols_CB'')',...
  1511. 'Interruptible','off','BusyAction','Queue',...
  1512. 'Position',[090 180 155 020].*WS);
  1513. H = [H,h];
  1514. h = uicontrol(F,'Style','Pushbutton','String','...submit',...
  1515. 'Tag', 'submit',...
  1516. 'FontSize',FS(8),...
  1517. 'ForegroundColor','c',...
  1518. 'Position',[245 180 050 020].*WS);
  1519. H = [H,h];
  1520. % ----------------
  1521. %-Errors & info boxes...
  1522. h = uicontrol(F,'Style','ListBox','Tag','D_ConErrs',...
  1523. 'ToolTipString','contrast parsing errors',...
  1524. 'FontName',PF.courier,'FontSize',FS(7),...
  1525. 'ForegroundColor','r',...
  1526. 'BackgroundColor',[1 1 1]*.7,...
  1527. 'Enable','on','Max',2,'Value',[],...
  1528. 'Position',[027 127 268 042].*WS);
  1529. H = [H,h];
  1530. h = uicontrol(F,'Style','ListBox','Tag','D_ConInfo',...
  1531. 'ToolTipString','contrast parsing info',...
  1532. 'FontName',PF.courier,'FontSize',FS(7),...
  1533. 'ForegroundColor','g',...
  1534. 'BackgroundColor',[1 1 1]*.7,...
  1535. 'Enable','on','Max',2,'Value',[],...
  1536. 'Position',[027 085 268 042].*WS);
  1537. H = [H,h];
  1538. % ----------------
  1539. %-Control buttons & status area...
  1540. h = uicontrol(F,'Style','Pushbutton','String','Reset',...
  1541. 'Tag','D_Reset',...
  1542. 'ToolTipString','reset definition interface',...
  1543. 'ForegroundColor','b',...
  1544. 'Callback','spm_conman(''D_Reset_CB'')',...
  1545. 'Interruptible','off','BusyAction','Cancel',...
  1546. 'Position',[140 053 050 022].*WS);
  1547. H = [H,h];
  1548. h = uicontrol(F,'Style','Pushbutton','String','Cancel',...
  1549. 'Tag','D_Cancel',...
  1550. 'ToolTipString','cancel contrast definition',...
  1551. 'ForegroundColor','r',...
  1552. 'Callback','spm_conman(''D_Cancel_CB'')',...
  1553. 'Interruptible','off','BusyAction','Cancel',...
  1554. 'Position',[195 053 050 022].*WS);
  1555. H = [H,h];
  1556. h = uicontrol(F,'Style','Pushbutton','String','OK',...
  1557. 'Tag','D_OK',...
  1558. 'ToolTipString','OK - press to accept newly defined contrast',...
  1559. 'ForegroundColor','m',...
  1560. 'Callback','spm_conman(''D_OK_CB'')',...
  1561. 'Interruptible','off','BusyAction','Cancel',...
  1562. 'Position',[250 053 050 022].*WS);
  1563. H = [H,h];
  1564. set(findobj(H,'flat','Tag','DefineNew'),'UserData',H)
  1565. %-Finish up
  1566. %------------------------------------------------------------------
  1567. set(0,'CurrentFigure',cF)
  1568. varargout = {F,struct( 'hConList', hConList,...
  1569. 'hDesMtxAx', hDesMtxAx,...
  1570. 'hParEstAx', hParEstAx,...
  1571. 'hPrompt', hPrompt,...
  1572. 'hSTATmode', hSTATmode,...
  1573. 'hStatLin', hStatLin,...
  1574. 'hNew', hNew )};
  1575. %======================================================================
  1576. otherwise %-unknown action
  1577. %======================================================================
  1578. error(['Illegal Action string: ',varargin{1}])
  1579. %==========================================================================
  1580. end % - E N D
  1581. %==========================================================================