This is a static copy of a profile reportHome
menu>local_GUImenu (5 calls, 0.844 sec)
Generated 15-Mar-2007 12:01:42 using real time.
M-subfunction in file C:\Program Files\MATLAB71\toolbox\matlab\uitools\menu.m
[Copy to new window for comparing multiple runs]
Parents (calling functions)
Function Name | Function Type | Calls |
menu | M-function | 5 |
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
284 | waitfor(gcf,'userdata') | 5 | 0.453 s | 53.7% |  |
279 | set( menuFig, 'Visible', 'on' ... | 5 | 0.156 s | 18.5% |  |
155 | menuFig = figure( 'Units' ... | 5 | 0.078 s | 9.3% |  |
168 | hText = uicontrol( ... | 5 | 0.047 s | 5.6% |  |
289 | k = get(gcf,'userdata'); | 5 | 0.031 s | 3.7% |  |
Other lines & overhead | | | 0.078 s | 9.3% |  |
Totals | | | 0.844 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
gcf | M-function | 15 | 0.031 s | 3.7% |  |
int2str | M-function | 12 | 0 s | 0% |  |
num2cell | M-function | 5 | 0 s | 0% |  |
timercb | M-function | 11 | 0 s | 0% |  |
Self time (built-ins, overhead, etc.) | | | 0.813 s | 96.3% |  |
Totals | | | 0.844 s | 100% | |
M-Lint results
Line number | Message |
191 | Array 'hBtn' might be grown using indexing. Consider preallocating for speed. |
250 | Use of brackets [] is unnecessary. Use parentheses to group, if needed. |
252 | Use of brackets [] is unnecessary. Use parentheses to group, if needed. |
Coverage results
[ Show coverage for parent directory ]
Total lines in file | 171 |
Non-code lines (comments, blank lines) | 120 |
Code lines (lines that can run) | 51 |
Code lines that did run | 51 |
Code lines that did not run | 0 |
Coverage (did run/can run) | 100.00 % |
Function listing
time calls line
124 function k = local_GUImenu( xHeader, xcItems )
125
126 % local function to display a Handle Graphics menu and return the user's
127 % selection from that menu as an index into the xcItems cell array
128
129 %=========================================================================
130 % SET UP
131 %=========================================================================
132 % Set spacing and sizing parameters for the GUI elements
133 %-------------------------------------------------------------------------
< 0.01 5 134 MenuUnits = 'points'; % units used for all HG objects
< 0.01 5 135 textPadding = [18 8]; % extra [Width Height] on uicontrols to pad text
< 0.01 5 136 uiGap = 5; % space between uicontrols
< 0.01 5 137 uiBorder = 5; % space between edge of figure and any uicontol
< 0.01 5 138 winTopGap = 50; % gap between top of screen and top of figure **
< 0.01 5 139 winLeftGap = 15; % gap between side of screen and side of figure **
140
141 % ** "figure" ==> viewable figure. You must allow space for the OS to add
142 % a title bar (aprx 42 points on Mac and Windows) and a window border
143 % (usu 2-6 points). Otherwise user cannot move the window.
144
145 %-------------------------------------------------------------------------
146 % Calculate the number of items in the menu
147 %-------------------------------------------------------------------------
5 148 numItems = length( xcItems );
149
150 %=========================================================================
151 % BUILD
152 %=========================================================================
153 % Create a generically-sized invisible figure window
154 %------------------------------------------------------------------------
0.08 5 155 menuFig = figure( 'Units' ,MenuUnits, ...
156 'Visible' ,'off', ...
157 'NumberTitle' ,'off', ...
158 'Name' ,'MENU', ...
159 'Resize' ,'off', ...
160 'Colormap' ,[], ...
161 'Menubar' ,'none',...
162 'Toolbar' ,'none',...
163 'CloseRequestFcn','set(gcbf,''userdata'',0)');
164
165 %------------------------------------------------------------------------
166 % Add generically-sized header text with same background color as figure
167 %------------------------------------------------------------------------
0.05 5 168 hText = uicontrol( ...
169 'style' ,'text', ...
170 'string' ,xHeader, ...
171 'units' ,MenuUnits, ...
172 'Position' ,[ 100 100 100 20 ], ...
173 'Horizontal' ,'center',...
174 'BackGround' ,get(menuFig,'Color') );
175
176 % Record extent of text string
5 177 maxsize = get( hText, 'Extent' );
< 0.01 5 178 textWide = maxsize(3);
< 0.01 5 179 textHigh = maxsize(4);
180
181 %------------------------------------------------------------------------
182 % Add generically-spaced buttons below the header text
183 %------------------------------------------------------------------------
184 % Loop to add buttons in reverse order (to automatically initialize numitems).
185 % Note that buttons may overlap, but are placed in correct position relative
186 % to each other. They will be resized and spaced evenly later on.
187
5 188 for idx = numItems : -1 : 1; % start from top of screen and go down
< 0.01 12 189 n = numItems - idx + 1; % start from 1st button and go to last
190 % make a button
0.03 12 191 hBtn(n) = uicontrol( ...
192 'units' ,MenuUnits, ...
193 'position' ,[uiBorder uiGap*idx textHigh textWide], ...
194 'callback' ,['set(gcf,''userdata'',',int2str(n),')'], ...
195 'string' ,xcItems{n} );
12 196 end % for
197
198 %=========================================================================
199 % TWEAK
200 %=========================================================================
201 % Calculate Optimal UIcontrol dimensions based on max text size
202 %------------------------------------------------------------------------
5 203 cAllExtents = get( hBtn, {'Extent'} ); % put all data in a cell array
5 204 AllExtents = cat( 1, cAllExtents{:} ); % convert to an n x 3 matrix
5 205 maxsize = max( AllExtents(:,3:4) ); % calculate the largest width & height
5 206 maxsize = maxsize + textPadding; % add some blank space around text
< 0.01 5 207 btnHigh = maxsize(2);
< 0.01 5 208 btnWide = maxsize(1);
209
210 %------------------------------------------------------------------------
211 % Retrieve screen dimensions (in correct units)
212 %------------------------------------------------------------------------
5 213 oldUnits = get(0,'Units'); % remember old units
5 214 set( 0, 'Units', MenuUnits ); % convert to desired units
5 215 screensize = get(0,'ScreenSize'); % record screensize
5 216 set( 0, 'Units', oldUnits ); % convert back to old units
217
218 %------------------------------------------------------------------------
219 % How many rows and columns of buttons will fit in the screen?
220 % Note: vertical space for buttons is the critical dimension
221 % --window can't be moved up, but can be moved side-to-side
222 %------------------------------------------------------------------------
< 0.01 5 223 openSpace = screensize(4) - winTopGap - 2*uiBorder - textHigh;
< 0.01 5 224 numRows = min( floor( openSpace/(btnHigh + uiGap) ), numItems );
< 0.01 5 225 if numRows == 0; numRows = 1; end % Trivial case--but very safe to do
< 0.01 5 226 numCols = ceil( numItems/numRows );
227
228 %------------------------------------------------------------------------
229 % Resize figure to place it in top left of screen
230 %------------------------------------------------------------------------
231 % Calculate the window size needed to display all buttons
< 0.01 5 232 winHigh = numRows*(btnHigh + uiGap) + textHigh + 2*uiBorder;
< 0.01 5 233 winWide = numCols*(btnWide) + (numCols - 1)*uiGap + 2*uiBorder;
234
235 % Make sure the text header fits
< 0.01 5 236 if winWide < (2*uiBorder + textWide),
< 0.01 5 237 winWide = 2*uiBorder + textWide;
< 0.01 5 238 end
239
240 % Determine final placement coordinates for bottom of figure window
< 0.01 5 241 bottom = screensize(4) - (winHigh + winTopGap);
242
243 % Set figure window position
5 244 set( menuFig, 'Position', [winLeftGap bottom winWide winHigh] );
245
246 %------------------------------------------------------------------------
247 % Size uicontrols to fit everyone in the window and see all text
248 %------------------------------------------------------------------------
249 % Calculate coordinates of bottom-left corner of all buttons
0.02 5 250 xPos = ( uiBorder + [0:numCols-1]'*( btnWide + uiGap )*ones(1,numRows) )';
5 251 xPos = xPos(1:numItems); % [ all 1st col; all 2nd col; ...; all nth col ]
5 252 yPos = ( uiBorder + [numRows-1:-1:0]'*( btnHigh + uiGap )*ones(1,numCols) );
5 253 yPos = yPos(1:numItems); % [ rows 1:m; rows 1:m; ...; rows 1:m ]
254
255 % Combine with desired button size to get a cell array of position vectors
5 256 allBtn = ones(numItems,1);
5 257 uiPosMtx = [ xPos(:), yPos(:), btnWide*allBtn, btnHigh*allBtn ];
5 258 cUIPos = num2cell( uiPosMtx( 1:numItems, : ), 2 );
259
260 % adjust all buttons
0.02 5 261 set( hBtn, {'Position'}, cUIPos );
262
263 %------------------------------------------------------------------------
264 % Align the Text and Buttons horizontally and distribute them vertically
265 %------------------------------------------------------------------------
266
267 % Calculate placement position of the Header
< 0.01 5 268 textWide = winWide - 2*uiBorder;
269
270 % Move Header text into correct position near the top of figure
5 271 set( hText, ...
272 'Position', [ uiBorder winHigh-uiBorder-textHigh textWide textHigh ] );
273
274 %=========================================================================
275 % ACTIVATE
276 %=========================================================================
277 % Make figure visible
278 %------------------------------------------------------------------------
0.16 5 279 set( menuFig, 'Visible', 'on' );
280
281 %------------------------------------------------------------------------
282 % Wait for choice to be made (i.e UserData must be assigned)...
283 %------------------------------------------------------------------------
0.45 5 284 waitfor(gcf,'userdata')
285
286 %------------------------------------------------------------------------
287 % ...selection has been made. Assign k and delete the Menu figure
288 %------------------------------------------------------------------------
0.03 5 289 k = get(gcf,'userdata');
0.02 5 290 delete(menuFig)
291
292 %%#########################################################################
293 % END : local function local_GUImenu
294 %%#########################################################################