annotate toolboxes/FullBNT-1.0.7/KPMtools/exportfig.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function varargout = exportfig(varargin)
wolffd@0 2 %EXPORTFIG Export a figure.
wolffd@0 3 % EXPORTFIG(H, FILENAME) writes the figure H to FILENAME. H is
wolffd@0 4 % a figure handle and FILENAME is a string that specifies the
wolffd@0 5 % name of the output file.
wolffd@0 6 %
wolffd@0 7 % EXPORTFIG(H, FILENAME, OPTIONS) writes the figure H to FILENAME
wolffd@0 8 % with options initially specified by the structure OPTIONS. The
wolffd@0 9 % field names of OPTIONS must be legal parameters listed below
wolffd@0 10 % and the field values must be legal values for the corresponding
wolffd@0 11 % parameter. Default options can be set in releases prior to R12
wolffd@0 12 % by storing the OPTIONS structure in the root object's appdata
wolffd@0 13 % with the command
wolffd@0 14 % setappdata(0,'exportfigdefaults', OPTIONS)
wolffd@0 15 % and for releases after R12 by setting the preference with the
wolffd@0 16 % command
wolffd@0 17 % setpref('exportfig', 'defaults', OPTIONS)
wolffd@0 18 %
wolffd@0 19 % EXPORTFIG(...,PARAM1,VAL1,PARAM2,VAL2,...) specifies
wolffd@0 20 % parameters that control various characteristics of the output
wolffd@0 21 % file. Any parameter value can be the string 'auto' which means
wolffd@0 22 % the parameter uses the default factory behavior, overriding
wolffd@0 23 % any other default for the parameter.
wolffd@0 24 %
wolffd@0 25 % Format Paramter:
wolffd@0 26 % 'Format' a string
wolffd@0 27 % specifies the output format. Defaults to 'eps'. For a
wolffd@0 28 % list of export formats type 'help print'.
wolffd@0 29 % 'Preview' one of the strings 'none', 'tiff'
wolffd@0 30 % specifies a preview for EPS files. Defaults to 'none'.
wolffd@0 31 %
wolffd@0 32 % Size Parameters:
wolffd@0 33 % 'Width' a positive scalar
wolffd@0 34 % specifies the width in the figure's PaperUnits
wolffd@0 35 % 'Height' a positive scalar
wolffd@0 36 % specifies the height in the figure's PaperUnits
wolffd@0 37 % 'Bounds' one of the strings 'tight', 'loose'
wolffd@0 38 % specifies a tight or loose bounding box. Defaults to 'tight'.
wolffd@0 39 % 'Reference' an axes handle or a string
wolffd@0 40 % specifies that the width and height parameters
wolffd@0 41 % are relative to the given axes. If a string is
wolffd@0 42 % specified then it must evaluate to an axes handle.
wolffd@0 43 %
wolffd@0 44 % Specifying only one dimension sets the other dimension
wolffd@0 45 % so that the exported aspect ratio is the same as the
wolffd@0 46 % figure's or reference axes' current aspect ratio.
wolffd@0 47 % If neither dimension is specified the size defaults to
wolffd@0 48 % the width and height from the figure's or reference
wolffd@0 49 % axes' size. Tight bounding boxes are only computed for
wolffd@0 50 % 2-D views and in that case the computed bounds enclose all
wolffd@0 51 % text objects.
wolffd@0 52 %
wolffd@0 53 % Rendering Parameters:
wolffd@0 54 % 'Color' one of the strings 'bw', 'gray', 'cmyk'
wolffd@0 55 % 'bw' specifies that lines and text are exported in
wolffd@0 56 % black and all other objects in grayscale
wolffd@0 57 % 'gray' specifies that all objects are exported in grayscale
wolffd@0 58 % 'rgb' specifies that all objects are exported in color
wolffd@0 59 % using the RGB color space
wolffd@0 60 % 'cmyk' specifies that all objects are exported in color
wolffd@0 61 % using the CMYK color space
wolffd@0 62 % 'Renderer' one of 'painters', 'zbuffer', 'opengl'
wolffd@0 63 % specifies the renderer to use
wolffd@0 64 % 'Resolution' a positive scalar
wolffd@0 65 % specifies the resolution in dots-per-inch.
wolffd@0 66 % 'LockAxes' one of 0 or 1
wolffd@0 67 % specifies that all axes limits and ticks should be fixed
wolffd@0 68 % while exporting.
wolffd@0 69 %
wolffd@0 70 % The default color setting is 'bw'.
wolffd@0 71 %
wolffd@0 72 % Font Parameters:
wolffd@0 73 % 'FontMode' one of the strings 'scaled', 'fixed'
wolffd@0 74 % 'FontSize' a positive scalar
wolffd@0 75 % in 'scaled' mode multiplies with the font size of each
wolffd@0 76 % text object to obtain the exported font size
wolffd@0 77 % in 'fixed' mode specifies the font size of all text
wolffd@0 78 % objects in points
wolffd@0 79 % 'DefaultFixedFontSize' a positive scalar
wolffd@0 80 % in 'fixed' mode specified the default font size in
wolffd@0 81 % points
wolffd@0 82 % 'FontSizeMin' a positive scalar
wolffd@0 83 % specifies the minimum font size allowed after scaling
wolffd@0 84 % 'FontSizeMax' a positive scalar
wolffd@0 85 % specifies the maximum font size allowed after scaling
wolffd@0 86 % 'FontEncoding' one of the strings 'latin1', 'adobe'
wolffd@0 87 % specifies the character encoding of the font
wolffd@0 88 % 'SeparateText' one of 0 or 1
wolffd@0 89 % specifies that the text objects are stored in separate
wolffd@0 90 % file as EPS with the base filename having '_t' appended.
wolffd@0 91 %
wolffd@0 92 % If FontMode is 'scaled' but FontSize is not specified then a
wolffd@0 93 % scaling factor is computed from the ratio of the size of the
wolffd@0 94 % exported figure to the size of the actual figure.
wolffd@0 95 %
wolffd@0 96 % The default 'FontMode' setting is 'scaled'.
wolffd@0 97 %
wolffd@0 98 % Line Width Parameters:
wolffd@0 99 % 'LineMode' one of the strings 'scaled', 'fixed'
wolffd@0 100 % 'LineWidth' a positive scalar
wolffd@0 101 % 'DefaultFixedLineWidth' a positive scalar
wolffd@0 102 % 'LineWidthMin' a positive scalar
wolffd@0 103 % specifies the minimum line width allowed after scaling
wolffd@0 104 % 'LineWidthMax' a positive scalar
wolffd@0 105 % specifies the maximum line width allowed after scaling
wolffd@0 106 % The semantics of 'Line' parameters are exactly the
wolffd@0 107 % same as the corresponding 'Font' parameters, except that
wolffd@0 108 % they apply to line widths instead of font sizes.
wolffd@0 109 %
wolffd@0 110 % Style Map Parameter:
wolffd@0 111 % 'LineStyleMap' one of [], 'bw', or a function name or handle
wolffd@0 112 % specifies how to map line colors to styles. An empty
wolffd@0 113 % style map means styles are not changed. The style map
wolffd@0 114 % 'bw' is a built-in mapping that maps lines with the same
wolffd@0 115 % color to the same style and otherwise cycles through the
wolffd@0 116 % available styles. A user-specified map is a function
wolffd@0 117 % that takes as input a cell array of line objects and
wolffd@0 118 % outputs a cell array of line style strings. The default
wolffd@0 119 % map is [].
wolffd@0 120 %
wolffd@0 121 % Examples:
wolffd@0 122 % exportfig(gcf,'fig1.eps','height',3);
wolffd@0 123 % Exports the current figure to the file named 'fig1.eps' with
wolffd@0 124 % a height of 3 inches (assuming the figure's PaperUnits is
wolffd@0 125 % inches) and an aspect ratio the same as the figure's aspect
wolffd@0 126 % ratio on screen.
wolffd@0 127 %
wolffd@0 128 % opts = struct('FontMode','fixed','FontSize',10,'height',3);
wolffd@0 129 % exportfig(gcf, 'fig2.eps', opts, 'height', 5);
wolffd@0 130 % Exports the current figure to 'fig2.eps' with all
wolffd@0 131 % text in 10 point fonts and with height 5 inches.
wolffd@0 132 %
wolffd@0 133 % See also PREVIEWFIG, APPLYTOFIG, RESTOREFIG, PRINT.
wolffd@0 134
wolffd@0 135 % Copyright 2000 Ben Hinkle
wolffd@0 136 % Email bug reports and comments to bhinkle@mathworks.com
wolffd@0 137
wolffd@0 138 if (nargin < 2)
wolffd@0 139 error('Too few input arguments');
wolffd@0 140 end
wolffd@0 141
wolffd@0 142 % exportfig(H, filename, [options,] ...)
wolffd@0 143 H = varargin{1};
wolffd@0 144 if ~LocalIsHG(H,'figure')
wolffd@0 145 error('First argument must be a handle to a figure.');
wolffd@0 146 end
wolffd@0 147 filename = varargin{2};
wolffd@0 148 if ~ischar(filename)
wolffd@0 149 error('Second argument must be a string.');
wolffd@0 150 end
wolffd@0 151 paramPairs = {varargin{3:end}};
wolffd@0 152 if nargin > 2
wolffd@0 153 if isstruct(paramPairs{1})
wolffd@0 154 pcell = LocalToCell(paramPairs{1});
wolffd@0 155 paramPairs = {pcell{:}, paramPairs{2:end}};
wolffd@0 156 end
wolffd@0 157 end
wolffd@0 158 verstr = version;
wolffd@0 159 majorver = str2num(verstr(1));
wolffd@0 160 defaults = [];
wolffd@0 161 if majorver > 5
wolffd@0 162 if ispref('exportfig','defaults')
wolffd@0 163 defaults = getpref('exportfig','defaults');
wolffd@0 164 end
wolffd@0 165 elseif exist('getappdata')
wolffd@0 166 defaults = getappdata(0,'exportfigdefaults');
wolffd@0 167 end
wolffd@0 168 if ~isempty(defaults)
wolffd@0 169 dcell = LocalToCell(defaults);
wolffd@0 170 paramPairs = {dcell{:}, paramPairs{:}};
wolffd@0 171 end
wolffd@0 172
wolffd@0 173 % Do some validity checking on param-value pairs
wolffd@0 174 if (rem(length(paramPairs),2) ~= 0)
wolffd@0 175 error(['Invalid input syntax. Optional parameters and values' ...
wolffd@0 176 ' must be in pairs.']);
wolffd@0 177 end
wolffd@0 178
wolffd@0 179 auto.format = 'eps';
wolffd@0 180 auto.preview = 'none';
wolffd@0 181 auto.width = -1;
wolffd@0 182 auto.height = -1;
wolffd@0 183 auto.color = 'bw';
wolffd@0 184 auto.defaultfontsize=10;
wolffd@0 185 auto.fontsize = -1;
wolffd@0 186 auto.fontmode='scaled';
wolffd@0 187 auto.fontmin = 8;
wolffd@0 188 auto.fontmax = 60;
wolffd@0 189 auto.defaultlinewidth = 1.0;
wolffd@0 190 auto.linewidth = -1;
wolffd@0 191 auto.linemode=[];
wolffd@0 192 auto.linemin = 0.5;
wolffd@0 193 auto.linemax = 100;
wolffd@0 194 auto.fontencoding = 'latin1';
wolffd@0 195 auto.renderer = [];
wolffd@0 196 auto.resolution = [];
wolffd@0 197 auto.stylemap = [];
wolffd@0 198 auto.applystyle = 0;
wolffd@0 199 auto.refobj = -1;
wolffd@0 200 auto.bounds = 'tight';
wolffd@0 201 explicitbounds = 0;
wolffd@0 202 auto.lockaxes = 1;
wolffd@0 203 auto.separatetext = 0;
wolffd@0 204 opts = auto;
wolffd@0 205
wolffd@0 206 % Process param-value pairs
wolffd@0 207 args = {};
wolffd@0 208 for k = 1:2:length(paramPairs)
wolffd@0 209 param = lower(paramPairs{k});
wolffd@0 210 if ~ischar(param)
wolffd@0 211 error('Optional parameter names must be strings');
wolffd@0 212 end
wolffd@0 213 value = paramPairs{k+1};
wolffd@0 214
wolffd@0 215 switch (param)
wolffd@0 216 case 'format'
wolffd@0 217 opts.format = LocalCheckAuto(lower(value),auto.format);
wolffd@0 218 if strcmp(opts.format,'preview')
wolffd@0 219 error(['Format ''preview'' no longer supported. Use PREVIEWFIG' ...
wolffd@0 220 ' instead.']);
wolffd@0 221 end
wolffd@0 222 case 'preview'
wolffd@0 223 opts.preview = LocalCheckAuto(lower(value),auto.preview);
wolffd@0 224 if ~strcmp(opts.preview,{'none','tiff'})
wolffd@0 225 error('Preview must be ''none'' or ''tiff''.');
wolffd@0 226 end
wolffd@0 227 case 'width'
wolffd@0 228 opts.width = LocalToNum(value, auto.width);
wolffd@0 229 if ~ischar(value) | ~strcmp(value,'auto')
wolffd@0 230 if ~LocalIsPositiveScalar(opts.width)
wolffd@0 231 error('Width must be a numeric scalar > 0');
wolffd@0 232 end
wolffd@0 233 end
wolffd@0 234 case 'height'
wolffd@0 235 opts.height = LocalToNum(value, auto.height);
wolffd@0 236 if ~ischar(value) | ~strcmp(value,'auto')
wolffd@0 237 if(~LocalIsPositiveScalar(opts.height))
wolffd@0 238 error('Height must be a numeric scalar > 0');
wolffd@0 239 end
wolffd@0 240 end
wolffd@0 241 case 'color'
wolffd@0 242 opts.color = LocalCheckAuto(lower(value),auto.color);
wolffd@0 243 if ~strcmp(opts.color,{'bw','gray','rgb','cmyk'})
wolffd@0 244 error('Color must be ''bw'', ''gray'',''rgb'' or ''cmyk''.');
wolffd@0 245 end
wolffd@0 246 case 'fontmode'
wolffd@0 247 opts.fontmode = LocalCheckAuto(lower(value),auto.fontmode);
wolffd@0 248 if ~strcmp(opts.fontmode,{'scaled','fixed'})
wolffd@0 249 error('FontMode must be ''scaled'' or ''fixed''.');
wolffd@0 250 end
wolffd@0 251 case 'fontsize'
wolffd@0 252 opts.fontsize = LocalToNum(value,auto.fontsize);
wolffd@0 253 if ~ischar(value) | ~strcmp(value,'auto')
wolffd@0 254 if ~LocalIsPositiveScalar(opts.fontsize)
wolffd@0 255 error('FontSize must be a numeric scalar > 0');
wolffd@0 256 end
wolffd@0 257 end
wolffd@0 258 case 'defaultfixedfontsize'
wolffd@0 259 opts.defaultfontsize = LocalToNum(value,auto.defaultfontsize);
wolffd@0 260 if ~ischar(value) | ~strcmp(value,'auto')
wolffd@0 261 if ~LocalIsPositiveScalar(opts.defaultfontsize)
wolffd@0 262 error('DefaultFixedFontSize must be a numeric scalar > 0');
wolffd@0 263 end
wolffd@0 264 end
wolffd@0 265 case 'fontsizemin'
wolffd@0 266 opts.fontmin = LocalToNum(value,auto.fontmin);
wolffd@0 267 if ~ischar(value) | ~strcmp(value,'auto')
wolffd@0 268 if ~LocalIsPositiveScalar(opts.fontmin)
wolffd@0 269 error('FontSizeMin must be a numeric scalar > 0');
wolffd@0 270 end
wolffd@0 271 end
wolffd@0 272 case 'fontsizemax'
wolffd@0 273 opts.fontmax = LocalToNum(value,auto.fontmax);
wolffd@0 274 if ~ischar(value) | ~strcmp(value,'auto')
wolffd@0 275 if ~LocalIsPositiveScalar(opts.fontmax)
wolffd@0 276 error('FontSizeMax must be a numeric scalar > 0');
wolffd@0 277 end
wolffd@0 278 end
wolffd@0 279 case 'fontencoding'
wolffd@0 280 opts.fontencoding = LocalCheckAuto(lower(value),auto.fontencoding);
wolffd@0 281 if ~strcmp(opts.fontencoding,{'latin1','adobe'})
wolffd@0 282 error('FontEncoding must be ''latin1'' or ''adobe''.');
wolffd@0 283 end
wolffd@0 284 case 'linemode'
wolffd@0 285 opts.linemode = LocalCheckAuto(lower(value),auto.linemode);
wolffd@0 286 if ~strcmp(opts.linemode,{'scaled','fixed'})
wolffd@0 287 error('LineMode must be ''scaled'' or ''fixed''.');
wolffd@0 288 end
wolffd@0 289 case 'linewidth'
wolffd@0 290 opts.linewidth = LocalToNum(value,auto.linewidth);
wolffd@0 291 if ~ischar(value) | ~strcmp(value,'auto')
wolffd@0 292 if ~LocalIsPositiveScalar(opts.linewidth)
wolffd@0 293 error('LineWidth must be a numeric scalar > 0');
wolffd@0 294 end
wolffd@0 295 end
wolffd@0 296 case 'defaultfixedlinewidth'
wolffd@0 297 opts.defaultlinewidth = LocalToNum(value,auto.defaultlinewidth);
wolffd@0 298 if ~ischar(value) | ~strcmp(value,'auto')
wolffd@0 299 if ~LocalIsPositiveScalar(opts.defaultlinewidth)
wolffd@0 300 error(['DefaultFixedLineWidth must be a numeric scalar >' ...
wolffd@0 301 ' 0']);
wolffd@0 302 end
wolffd@0 303 end
wolffd@0 304 case 'linewidthmin'
wolffd@0 305 opts.linemin = LocalToNum(value,auto.linemin);
wolffd@0 306 if ~ischar(value) | ~strcmp(value,'auto')
wolffd@0 307 if ~LocalIsPositiveScalar(opts.linemin)
wolffd@0 308 error('LineWidthMin must be a numeric scalar > 0');
wolffd@0 309 end
wolffd@0 310 end
wolffd@0 311 case 'linewidthmax'
wolffd@0 312 opts.linemax = LocalToNum(value,auto.linemax);
wolffd@0 313 if ~ischar(value) | ~strcmp(value,'auto')
wolffd@0 314 if ~LocalIsPositiveScalar(opts.linemax)
wolffd@0 315 error('LineWidthMax must be a numeric scalar > 0');
wolffd@0 316 end
wolffd@0 317 end
wolffd@0 318 case 'linestylemap'
wolffd@0 319 opts.stylemap = LocalCheckAuto(value,auto.stylemap);
wolffd@0 320 case 'renderer'
wolffd@0 321 opts.renderer = LocalCheckAuto(lower(value),auto.renderer);
wolffd@0 322 if ~ischar(value) | ~strcmp(value,'auto')
wolffd@0 323 if ~strcmp(opts.renderer,{'painters','zbuffer','opengl'})
wolffd@0 324 error(['Renderer must be ''painters'', ''zbuffer'' or' ...
wolffd@0 325 ' ''opengl''.']);
wolffd@0 326 end
wolffd@0 327 end
wolffd@0 328 case 'resolution'
wolffd@0 329 opts.resolution = LocalToNum(value,auto.resolution);
wolffd@0 330 if ~ischar(value) | ~strcmp(value,'auto')
wolffd@0 331 if ~(isnumeric(value) & (prod(size(value)) == 1) & (value >= 0));
wolffd@0 332 error('Resolution must be a numeric scalar >= 0');
wolffd@0 333 end
wolffd@0 334 end
wolffd@0 335 case 'applystyle' % means to apply the options and not export
wolffd@0 336 opts.applystyle = 1;
wolffd@0 337 case 'reference'
wolffd@0 338 if ischar(value)
wolffd@0 339 if strcmp(value,'auto')
wolffd@0 340 opts.refobj = auto.refobj;
wolffd@0 341 else
wolffd@0 342 opts.refobj = eval(value);
wolffd@0 343 end
wolffd@0 344 else
wolffd@0 345 opts.refobj = value;
wolffd@0 346 end
wolffd@0 347 if ~LocalIsHG(opts.refobj,'axes')
wolffd@0 348 error('Reference object must evaluate to an axes handle.');
wolffd@0 349 end
wolffd@0 350 case 'bounds'
wolffd@0 351 opts.bounds = LocalCheckAuto(lower(value),auto.bounds);
wolffd@0 352 explicitbounds = 1;
wolffd@0 353 if ~strcmp(opts.bounds,{'tight','loose'})
wolffd@0 354 error('Bounds must be ''tight'' or ''loose''.');
wolffd@0 355 end
wolffd@0 356 case 'lockaxes'
wolffd@0 357 opts.lockaxes = LocalToNum(value,auto.lockaxes);
wolffd@0 358 case 'separatetext'
wolffd@0 359 opts.separatetext = LocalToNum(value,auto.separatetext);
wolffd@0 360 otherwise
wolffd@0 361 error(['Unrecognized option ' param '.']);
wolffd@0 362 end
wolffd@0 363 end
wolffd@0 364
wolffd@0 365 % make sure figure is up-to-date
wolffd@0 366 drawnow;
wolffd@0 367
wolffd@0 368 allLines = findall(H, 'type', 'line');
wolffd@0 369 allText = findall(H, 'type', 'text');
wolffd@0 370 allAxes = findall(H, 'type', 'axes');
wolffd@0 371 allImages = findall(H, 'type', 'image');
wolffd@0 372 allLights = findall(H, 'type', 'light');
wolffd@0 373 allPatch = findall(H, 'type', 'patch');
wolffd@0 374 allSurf = findall(H, 'type', 'surface');
wolffd@0 375 allRect = findall(H, 'type', 'rectangle');
wolffd@0 376 allFont = [allText; allAxes];
wolffd@0 377 allColor = [allLines; allText; allAxes; allLights];
wolffd@0 378 allMarker = [allLines; allPatch; allSurf];
wolffd@0 379 allEdge = [allPatch; allSurf];
wolffd@0 380 allCData = [allImages; allPatch; allSurf];
wolffd@0 381
wolffd@0 382 old.objs = {};
wolffd@0 383 old.prop = {};
wolffd@0 384 old.values = {};
wolffd@0 385
wolffd@0 386 % Process format
wolffd@0 387 if strncmp(opts.format,'eps',3) & ~strcmp(opts.preview,'none')
wolffd@0 388 args = {args{:}, ['-' opts.preview]};
wolffd@0 389 end
wolffd@0 390
wolffd@0 391 hadError = 0;
wolffd@0 392 oldwarn = warning;
wolffd@0 393 try
wolffd@0 394
wolffd@0 395 % lock axes limits, ticks and labels if requested
wolffd@0 396 if opts.lockaxes
wolffd@0 397 old = LocalManualAxesMode(old, allAxes, 'TickMode');
wolffd@0 398 old = LocalManualAxesMode(old, allAxes, 'TickLabelMode');
wolffd@0 399 old = LocalManualAxesMode(old, allAxes, 'LimMode');
wolffd@0 400 end
wolffd@0 401
wolffd@0 402 % Process size parameters
wolffd@0 403 figurePaperUnits = get(H, 'PaperUnits');
wolffd@0 404 oldFigureUnits = get(H, 'Units');
wolffd@0 405 oldFigPos = get(H,'Position');
wolffd@0 406 set(H, 'Units', figurePaperUnits);
wolffd@0 407 figPos = get(H,'Position');
wolffd@0 408 refsize = figPos(3:4);
wolffd@0 409 if opts.refobj ~= -1
wolffd@0 410 oldUnits = get(opts.refobj, 'Units');
wolffd@0 411 set(opts.refobj, 'Units', figurePaperUnits);
wolffd@0 412 r = get(opts.refobj, 'Position');
wolffd@0 413 refsize = r(3:4);
wolffd@0 414 set(opts.refobj, 'Units', oldUnits);
wolffd@0 415 end
wolffd@0 416 aspectRatio = refsize(1)/refsize(2);
wolffd@0 417 if (opts.width == -1) & (opts.height == -1)
wolffd@0 418 opts.width = refsize(1);
wolffd@0 419 opts.height = refsize(2);
wolffd@0 420 elseif (opts.width == -1)
wolffd@0 421 opts.width = opts.height * aspectRatio;
wolffd@0 422 elseif (opts.height == -1)
wolffd@0 423 opts.height = opts.width / aspectRatio;
wolffd@0 424 end
wolffd@0 425 wscale = opts.width/refsize(1);
wolffd@0 426 hscale = opts.height/refsize(2);
wolffd@0 427 sizescale = min(wscale,hscale);
wolffd@0 428 old = LocalPushOldData(old,H,'PaperPositionMode', ...
wolffd@0 429 get(H,'PaperPositionMode'));
wolffd@0 430 set(H, 'PaperPositionMode', 'auto');
wolffd@0 431 newPos = [figPos(1) figPos(2)+figPos(4)*(1-hscale) ...
wolffd@0 432 wscale*figPos(3) hscale*figPos(4)];
wolffd@0 433 set(H, 'Position', newPos);
wolffd@0 434 set(H, 'Units', oldFigureUnits);
wolffd@0 435
wolffd@0 436 % process line-style map
wolffd@0 437 if ~isempty(opts.stylemap) & ~isempty(allLines)
wolffd@0 438 oldlstyle = LocalGetAsCell(allLines,'LineStyle');
wolffd@0 439 old = LocalPushOldData(old, allLines, {'LineStyle'}, ...
wolffd@0 440 oldlstyle);
wolffd@0 441 newlstyle = oldlstyle;
wolffd@0 442 if ischar(opts.stylemap) & strcmpi(opts.stylemap,'bw')
wolffd@0 443 newlstyle = LocalMapColorToStyle(allLines);
wolffd@0 444 else
wolffd@0 445 try
wolffd@0 446 newlstyle = feval(opts.stylemap,allLines);
wolffd@0 447 catch
wolffd@0 448 warning(['Skipping stylemap. ' lasterr]);
wolffd@0 449 end
wolffd@0 450 end
wolffd@0 451 set(allLines,{'LineStyle'},newlstyle);
wolffd@0 452 end
wolffd@0 453
wolffd@0 454 % Process rendering parameters
wolffd@0 455 switch (opts.color)
wolffd@0 456 case {'bw', 'gray'}
wolffd@0 457 if ~strcmp(opts.color,'bw') & strncmp(opts.format,'eps',3)
wolffd@0 458 opts.format = [opts.format 'c'];
wolffd@0 459 end
wolffd@0 460 args = {args{:}, ['-d' opts.format]};
wolffd@0 461
wolffd@0 462 %compute and set gray colormap
wolffd@0 463 oldcmap = get(H,'Colormap');
wolffd@0 464 newgrays = 0.30*oldcmap(:,1) + 0.59*oldcmap(:,2) + 0.11*oldcmap(:,3);
wolffd@0 465 newcmap = [newgrays newgrays newgrays];
wolffd@0 466 old = LocalPushOldData(old, H, 'Colormap', oldcmap);
wolffd@0 467 set(H, 'Colormap', newcmap);
wolffd@0 468
wolffd@0 469 %compute and set ColorSpec and CData properties
wolffd@0 470 old = LocalUpdateColors(allColor, 'color', old);
wolffd@0 471 old = LocalUpdateColors(allAxes, 'xcolor', old);
wolffd@0 472 old = LocalUpdateColors(allAxes, 'ycolor', old);
wolffd@0 473 old = LocalUpdateColors(allAxes, 'zcolor', old);
wolffd@0 474 old = LocalUpdateColors(allMarker, 'MarkerEdgeColor', old);
wolffd@0 475 old = LocalUpdateColors(allMarker, 'MarkerFaceColor', old);
wolffd@0 476 old = LocalUpdateColors(allEdge, 'EdgeColor', old);
wolffd@0 477 old = LocalUpdateColors(allEdge, 'FaceColor', old);
wolffd@0 478 old = LocalUpdateColors(allCData, 'CData', old);
wolffd@0 479
wolffd@0 480 case {'rgb','cmyk'}
wolffd@0 481 if strncmp(opts.format,'eps',3)
wolffd@0 482 opts.format = [opts.format 'c'];
wolffd@0 483 args = {args{:}, ['-d' opts.format]};
wolffd@0 484 if strcmp(opts.color,'cmyk')
wolffd@0 485 args = {args{:}, '-cmyk'};
wolffd@0 486 end
wolffd@0 487 else
wolffd@0 488 args = {args{:}, ['-d' opts.format]};
wolffd@0 489 end
wolffd@0 490 otherwise
wolffd@0 491 error('Invalid Color parameter');
wolffd@0 492 end
wolffd@0 493 if (~isempty(opts.renderer))
wolffd@0 494 args = {args{:}, ['-' opts.renderer]};
wolffd@0 495 end
wolffd@0 496 if (~isempty(opts.resolution)) | ~strncmp(opts.format,'eps',3)
wolffd@0 497 if isempty(opts.resolution)
wolffd@0 498 opts.resolution = 0;
wolffd@0 499 end
wolffd@0 500 args = {args{:}, ['-r' int2str(opts.resolution)]};
wolffd@0 501 end
wolffd@0 502
wolffd@0 503 % Process font parameters
wolffd@0 504 if ~isempty(opts.fontmode)
wolffd@0 505 oldfonts = LocalGetAsCell(allFont,'FontSize');
wolffd@0 506 oldfontunits = LocalGetAsCell(allFont,'FontUnits');
wolffd@0 507 set(allFont,'FontUnits','points');
wolffd@0 508 switch (opts.fontmode)
wolffd@0 509 case 'fixed'
wolffd@0 510 if (opts.fontsize == -1)
wolffd@0 511 set(allFont,'FontSize',opts.defaultfontsize);
wolffd@0 512 else
wolffd@0 513 set(allFont,'FontSize',opts.fontsize);
wolffd@0 514 end
wolffd@0 515 case 'scaled'
wolffd@0 516 if (opts.fontsize == -1)
wolffd@0 517 scale = sizescale;
wolffd@0 518 else
wolffd@0 519 scale = opts.fontsize;
wolffd@0 520 end
wolffd@0 521 newfonts = LocalScale(oldfonts,scale,opts.fontmin,opts.fontmax);
wolffd@0 522 set(allFont,{'FontSize'},newfonts);
wolffd@0 523 otherwise
wolffd@0 524 error('Invalid FontMode parameter');
wolffd@0 525 end
wolffd@0 526 old = LocalPushOldData(old, allFont, {'FontSize'}, oldfonts);
wolffd@0 527 old = LocalPushOldData(old, allFont, {'FontUnits'}, oldfontunits);
wolffd@0 528 end
wolffd@0 529 if strcmp(opts.fontencoding,'adobe') & strncmp(opts.format,'eps',3)
wolffd@0 530 args = {args{:}, '-adobecset'};
wolffd@0 531 end
wolffd@0 532
wolffd@0 533 % Process line parameters
wolffd@0 534 if ~isempty(opts.linemode)
wolffd@0 535 oldlines = LocalGetAsCell(allMarker,'LineWidth');
wolffd@0 536 old = LocalPushOldData(old, allMarker, {'LineWidth'}, oldlines);
wolffd@0 537 switch (opts.linemode)
wolffd@0 538 case 'fixed'
wolffd@0 539 if (opts.linewidth == -1)
wolffd@0 540 set(allMarker,'LineWidth',opts.defaultlinewidth);
wolffd@0 541 else
wolffd@0 542 set(allMarker,'LineWidth',opts.linewidth);
wolffd@0 543 end
wolffd@0 544 case 'scaled'
wolffd@0 545 if (opts.linewidth == -1)
wolffd@0 546 scale = sizescale;
wolffd@0 547 else
wolffd@0 548 scale = opts.linewidth;
wolffd@0 549 end
wolffd@0 550 newlines = LocalScale(oldlines, scale, opts.linemin, opts.linemax);
wolffd@0 551 set(allMarker,{'LineWidth'},newlines);
wolffd@0 552 end
wolffd@0 553 end
wolffd@0 554
wolffd@0 555 % adjust figure bounds to surround axes
wolffd@0 556 if strcmp(opts.bounds,'tight')
wolffd@0 557 if (~strncmp(opts.format,'eps',3) & LocalHas3DPlot(allAxes)) | ...
wolffd@0 558 (strncmp(opts.format,'eps',3) & opts.separatetext)
wolffd@0 559 if (explicitbounds == 1)
wolffd@0 560 warning(['Cannot compute ''tight'' bounds. Using ''loose''' ...
wolffd@0 561 ' bounds.']);
wolffd@0 562 end
wolffd@0 563 opts.bounds = 'loose';
wolffd@0 564 end
wolffd@0 565 end
wolffd@0 566 warning('off');
wolffd@0 567 if ~isempty(allAxes)
wolffd@0 568 if strncmp(opts.format,'eps',3)
wolffd@0 569 if strcmp(opts.bounds,'loose')
wolffd@0 570 args = {args{:}, '-loose'};
wolffd@0 571 end
wolffd@0 572 old = LocalPushOldData(old,H,'Position', oldFigPos);
wolffd@0 573 elseif strcmp(opts.bounds,'tight')
wolffd@0 574 oldaunits = LocalGetAsCell(allAxes,'Units');
wolffd@0 575 oldapos = LocalGetAsCell(allAxes,'Position');
wolffd@0 576 oldtunits = LocalGetAsCell(allText,'units');
wolffd@0 577 oldtpos = LocalGetAsCell(allText,'Position');
wolffd@0 578 set(allAxes,'units','points');
wolffd@0 579 apos = LocalGetAsCell(allAxes,'Position');
wolffd@0 580 oldunits = get(H,'Units');
wolffd@0 581 set(H,'units','points');
wolffd@0 582 origfr = get(H,'position');
wolffd@0 583 fr = [];
wolffd@0 584 for k=1:length(allAxes)
wolffd@0 585 if ~strcmpi(get(allAxes(k),'Tag'),'legend')
wolffd@0 586 axesR = apos{k};
wolffd@0 587 r = LocalAxesTightBoundingBox(axesR, allAxes(k));
wolffd@0 588 r(1:2) = r(1:2) + axesR(1:2);
wolffd@0 589 fr = LocalUnionRect(fr,r);
wolffd@0 590 end
wolffd@0 591 end
wolffd@0 592 if isempty(fr)
wolffd@0 593 fr = [0 0 origfr(3:4)];
wolffd@0 594 end
wolffd@0 595 for k=1:length(allAxes)
wolffd@0 596 ax = allAxes(k);
wolffd@0 597 r = apos{k};
wolffd@0 598 r(1:2) = r(1:2) - fr(1:2);
wolffd@0 599 set(ax,'Position',r);
wolffd@0 600 end
wolffd@0 601 old = LocalPushOldData(old, allAxes, {'Position'}, oldapos);
wolffd@0 602 old = LocalPushOldData(old, allText, {'Position'}, oldtpos);
wolffd@0 603 old = LocalPushOldData(old, allText, {'Units'}, oldtunits);
wolffd@0 604 old = LocalPushOldData(old, allAxes, {'Units'}, oldaunits);
wolffd@0 605 old = LocalPushOldData(old, H, 'Position', oldFigPos);
wolffd@0 606 old = LocalPushOldData(old, H, 'Units', oldFigureUnits);
wolffd@0 607 r = [origfr(1) origfr(2)+origfr(4)-fr(4) fr(3:4)];
wolffd@0 608 set(H,'Position',r);
wolffd@0 609 else
wolffd@0 610 args = {args{:}, '-loose'};
wolffd@0 611 old = LocalPushOldData(old,H,'Position', oldFigPos);
wolffd@0 612 end
wolffd@0 613 end
wolffd@0 614
wolffd@0 615 % Process text in a separate file if needed
wolffd@0 616 if opts.separatetext & ~opts.applystyle
wolffd@0 617 % First hide all text and export
wolffd@0 618 oldtvis = LocalGetAsCell(allText,'visible');
wolffd@0 619 set(allText,'visible','off');
wolffd@0 620 oldax = LocalGetAsCell(allAxes,'XTickLabel',1);
wolffd@0 621 olday = LocalGetAsCell(allAxes,'YTickLabel',1);
wolffd@0 622 oldaz = LocalGetAsCell(allAxes,'ZTickLabel',1);
wolffd@0 623 null = cell(length(oldax),1);
wolffd@0 624 [null{:}] = deal([]);
wolffd@0 625 set(allAxes,{'XTickLabel'},null);
wolffd@0 626 set(allAxes,{'YTickLabel'},null);
wolffd@0 627 set(allAxes,{'ZTickLabel'},null);
wolffd@0 628 print(H, filename, args{:});
wolffd@0 629 set(allText,{'Visible'},oldtvis);
wolffd@0 630 set(allAxes,{'XTickLabel'},oldax);
wolffd@0 631 set(allAxes,{'YTickLabel'},olday);
wolffd@0 632 set(allAxes,{'ZTickLabel'},oldaz);
wolffd@0 633 % Now hide all non-text and export as eps in painters
wolffd@0 634 [path, name, ext] = fileparts(filename);
wolffd@0 635 tfile = fullfile(path,[name '_t.eps']);
wolffd@0 636 tfile2 = fullfile(path,[name '_t2.eps']);
wolffd@0 637 foundRenderer = 0;
wolffd@0 638 for k=1:length(args)
wolffd@0 639 if strncmp('-d',args{k},2)
wolffd@0 640 args{k} = '-deps';
wolffd@0 641 elseif strncmp('-zbuffer',args{k},8) | ...
wolffd@0 642 strncmp('-opengl', args{k},6)
wolffd@0 643 args{k} = '-painters';
wolffd@0 644 foundRenderer = 1;
wolffd@0 645 end
wolffd@0 646 end
wolffd@0 647 if ~foundRenderer
wolffd@0 648 args = {args{:}, '-painters'};
wolffd@0 649 end
wolffd@0 650 allNonText = [allLines; allLights; allPatch; ...
wolffd@0 651 allImages; allSurf; allRect];
wolffd@0 652 oldvis = LocalGetAsCell(allNonText,'visible');
wolffd@0 653 oldc = LocalGetAsCell(allAxes,'color');
wolffd@0 654 oldaxg = LocalGetAsCell(allAxes,'XGrid');
wolffd@0 655 oldayg = LocalGetAsCell(allAxes,'YGrid');
wolffd@0 656 oldazg = LocalGetAsCell(allAxes,'ZGrid');
wolffd@0 657 [null{:}] = deal('off');
wolffd@0 658 set(allAxes,{'XGrid'},null);
wolffd@0 659 set(allAxes,{'YGrid'},null);
wolffd@0 660 set(allAxes,{'ZGrid'},null);
wolffd@0 661 set(allNonText,'Visible','off');
wolffd@0 662 set(allAxes,'Color','none');
wolffd@0 663 print(H, tfile2, args{:});
wolffd@0 664 set(allNonText,{'Visible'},oldvis);
wolffd@0 665 set(allAxes,{'Color'},oldc);
wolffd@0 666 set(allAxes,{'XGrid'},oldaxg);
wolffd@0 667 set(allAxes,{'YGrid'},oldayg);
wolffd@0 668 set(allAxes,{'ZGrid'},oldazg);
wolffd@0 669 %hack up the postscript file
wolffd@0 670 fid1 = fopen(tfile,'w');
wolffd@0 671 fid2 = fopen(tfile2,'r');
wolffd@0 672 line = fgetl(fid2);
wolffd@0 673 while ischar(line)
wolffd@0 674 if strncmp(line,'%%Title',7)
wolffd@0 675 fprintf(fid1,'%s\n',['%%Title: ', tfile]);
wolffd@0 676 elseif (length(line) < 3)
wolffd@0 677 fprintf(fid1,'%s\n',line);
wolffd@0 678 elseif ~strcmp(line(end-2:end),' PR') & ...
wolffd@0 679 ~strcmp(line(end-1:end),' L')
wolffd@0 680 fprintf(fid1,'%s\n',line);
wolffd@0 681 end
wolffd@0 682 line = fgetl(fid2);
wolffd@0 683 end
wolffd@0 684 fclose(fid1);
wolffd@0 685 fclose(fid2);
wolffd@0 686 delete(tfile2);
wolffd@0 687
wolffd@0 688 elseif ~opts.applystyle
wolffd@0 689 drawnow;
wolffd@0 690 print(H, filename, args{:});
wolffd@0 691 end
wolffd@0 692 warning(oldwarn);
wolffd@0 693
wolffd@0 694 catch
wolffd@0 695 warning(oldwarn);
wolffd@0 696 hadError = 1;
wolffd@0 697 end
wolffd@0 698
wolffd@0 699 % Restore figure settings
wolffd@0 700 if opts.applystyle
wolffd@0 701 varargout{1} = old;
wolffd@0 702 else
wolffd@0 703 for n=1:length(old.objs)
wolffd@0 704 if ~iscell(old.values{n}) & iscell(old.prop{n})
wolffd@0 705 old.values{n} = {old.values{n}};
wolffd@0 706 end
wolffd@0 707 set(old.objs{n}, old.prop{n}, old.values{n});
wolffd@0 708 end
wolffd@0 709 end
wolffd@0 710
wolffd@0 711 if hadError
wolffd@0 712 error(deblank(lasterr));
wolffd@0 713 end
wolffd@0 714
wolffd@0 715 %
wolffd@0 716 % Local Functions
wolffd@0 717 %
wolffd@0 718
wolffd@0 719 function outData = LocalPushOldData(inData, objs, prop, values)
wolffd@0 720 outData.objs = {objs, inData.objs{:}};
wolffd@0 721 outData.prop = {prop, inData.prop{:}};
wolffd@0 722 outData.values = {values, inData.values{:}};
wolffd@0 723
wolffd@0 724 function cellArray = LocalGetAsCell(fig,prop,allowemptycell);
wolffd@0 725 cellArray = get(fig,prop);
wolffd@0 726 if nargin < 3
wolffd@0 727 allowemptycell = 0;
wolffd@0 728 end
wolffd@0 729 if ~iscell(cellArray) & (allowemptycell | ~isempty(cellArray))
wolffd@0 730 cellArray = {cellArray};
wolffd@0 731 end
wolffd@0 732
wolffd@0 733 function newArray = LocalScale(inArray, scale, minv, maxv)
wolffd@0 734 n = length(inArray);
wolffd@0 735 newArray = cell(n,1);
wolffd@0 736 for k=1:n
wolffd@0 737 newArray{k} = min(maxv,max(minv,scale*inArray{k}(1)));
wolffd@0 738 end
wolffd@0 739
wolffd@0 740 function gray = LocalMapToGray1(color)
wolffd@0 741 gray = color;
wolffd@0 742 if ischar(color)
wolffd@0 743 switch color(1)
wolffd@0 744 case 'y'
wolffd@0 745 color = [1 1 0];
wolffd@0 746 case 'm'
wolffd@0 747 color = [1 0 1];
wolffd@0 748 case 'c'
wolffd@0 749 color = [0 1 1];
wolffd@0 750 case 'r'
wolffd@0 751 color = [1 0 0];
wolffd@0 752 case 'g'
wolffd@0 753 color = [0 1 0];
wolffd@0 754 case 'b'
wolffd@0 755 color = [0 0 1];
wolffd@0 756 case 'w'
wolffd@0 757 color = [1 1 1];
wolffd@0 758 case 'k'
wolffd@0 759 color = [0 0 0];
wolffd@0 760 end
wolffd@0 761 end
wolffd@0 762 if ~ischar(color)
wolffd@0 763 gray = 0.30*color(1) + 0.59*color(2) + 0.11*color(3);
wolffd@0 764 end
wolffd@0 765
wolffd@0 766 function newArray = LocalMapToGray(inArray);
wolffd@0 767 n = length(inArray);
wolffd@0 768 newArray = cell(n,1);
wolffd@0 769 for k=1:n
wolffd@0 770 color = inArray{k};
wolffd@0 771 if ~isempty(color)
wolffd@0 772 color = LocalMapToGray1(color);
wolffd@0 773 end
wolffd@0 774 if isempty(color) | ischar(color)
wolffd@0 775 newArray{k} = color;
wolffd@0 776 else
wolffd@0 777 newArray{k} = [color color color];
wolffd@0 778 end
wolffd@0 779 end
wolffd@0 780
wolffd@0 781 function newArray = LocalMapColorToStyle(inArray);
wolffd@0 782 inArray = LocalGetAsCell(inArray,'Color');
wolffd@0 783 n = length(inArray);
wolffd@0 784 newArray = cell(n,1);
wolffd@0 785 styles = {'-','--',':','-.'};
wolffd@0 786 uniques = [];
wolffd@0 787 nstyles = length(styles);
wolffd@0 788 for k=1:n
wolffd@0 789 gray = LocalMapToGray1(inArray{k});
wolffd@0 790 if isempty(gray) | ischar(gray) | gray < .05
wolffd@0 791 newArray{k} = '-';
wolffd@0 792 else
wolffd@0 793 if ~isempty(uniques) & any(gray == uniques)
wolffd@0 794 ind = find(gray==uniques);
wolffd@0 795 else
wolffd@0 796 uniques = [uniques gray];
wolffd@0 797 ind = length(uniques);
wolffd@0 798 end
wolffd@0 799 newArray{k} = styles{mod(ind-1,nstyles)+1};
wolffd@0 800 end
wolffd@0 801 end
wolffd@0 802
wolffd@0 803 function newArray = LocalMapCData(inArray);
wolffd@0 804 n = length(inArray);
wolffd@0 805 newArray = cell(n,1);
wolffd@0 806 for k=1:n
wolffd@0 807 color = inArray{k};
wolffd@0 808 if (ndims(color) == 3) & isa(color,'double')
wolffd@0 809 gray = 0.30*color(:,:,1) + 0.59*color(:,:,2) + 0.11*color(:,:,3);
wolffd@0 810 color(:,:,1) = gray;
wolffd@0 811 color(:,:,2) = gray;
wolffd@0 812 color(:,:,3) = gray;
wolffd@0 813 end
wolffd@0 814 newArray{k} = color;
wolffd@0 815 end
wolffd@0 816
wolffd@0 817 function outData = LocalUpdateColors(inArray, prop, inData)
wolffd@0 818 value = LocalGetAsCell(inArray,prop);
wolffd@0 819 outData.objs = {inData.objs{:}, inArray};
wolffd@0 820 outData.prop = {inData.prop{:}, {prop}};
wolffd@0 821 outData.values = {inData.values{:}, value};
wolffd@0 822 if (~isempty(value))
wolffd@0 823 if strcmp(prop,'CData')
wolffd@0 824 value = LocalMapCData(value);
wolffd@0 825 else
wolffd@0 826 value = LocalMapToGray(value);
wolffd@0 827 end
wolffd@0 828 set(inArray,{prop},value);
wolffd@0 829 end
wolffd@0 830
wolffd@0 831 function bool = LocalIsPositiveScalar(value)
wolffd@0 832 bool = isnumeric(value) & ...
wolffd@0 833 prod(size(value)) == 1 & ...
wolffd@0 834 value > 0;
wolffd@0 835
wolffd@0 836 function value = LocalToNum(value,auto)
wolffd@0 837 if ischar(value)
wolffd@0 838 if strcmp(value,'auto')
wolffd@0 839 value = auto;
wolffd@0 840 else
wolffd@0 841 value = str2num(value);
wolffd@0 842 end
wolffd@0 843 end
wolffd@0 844
wolffd@0 845 %convert a struct to {field1,val1,field2,val2,...}
wolffd@0 846 function c = LocalToCell(s)
wolffd@0 847 f = fieldnames(s);
wolffd@0 848 v = struct2cell(s);
wolffd@0 849 opts = cell(2,length(f));
wolffd@0 850 opts(1,:) = f;
wolffd@0 851 opts(2,:) = v;
wolffd@0 852 c = {opts{:}};
wolffd@0 853
wolffd@0 854 function c = LocalIsHG(obj,hgtype)
wolffd@0 855 c = 0;
wolffd@0 856 if (length(obj) == 1) & ishandle(obj)
wolffd@0 857 c = strcmp(get(obj,'type'),hgtype);
wolffd@0 858 end
wolffd@0 859
wolffd@0 860 function c = LocalHas3DPlot(a)
wolffd@0 861 zticks = LocalGetAsCell(a,'ZTickLabel');
wolffd@0 862 c = 0;
wolffd@0 863 for k=1:length(zticks)
wolffd@0 864 if ~isempty(zticks{k})
wolffd@0 865 c = 1;
wolffd@0 866 return;
wolffd@0 867 end
wolffd@0 868 end
wolffd@0 869
wolffd@0 870 function r = LocalUnionRect(r1,r2)
wolffd@0 871 if isempty(r1)
wolffd@0 872 r = r2;
wolffd@0 873 elseif isempty(r2)
wolffd@0 874 r = r1;
wolffd@0 875 elseif max(r2(3:4)) > 0
wolffd@0 876 left = min(r1(1),r2(1));
wolffd@0 877 bot = min(r1(2),r2(2));
wolffd@0 878 right = max(r1(1)+r1(3),r2(1)+r2(3));
wolffd@0 879 top = max(r1(2)+r1(4),r2(2)+r2(4));
wolffd@0 880 r = [left bot right-left top-bot];
wolffd@0 881 else
wolffd@0 882 r = r1;
wolffd@0 883 end
wolffd@0 884
wolffd@0 885 function c = LocalLabelsMatchTicks(labs,ticks)
wolffd@0 886 c = 0;
wolffd@0 887 try
wolffd@0 888 t1 = num2str(ticks(1));
wolffd@0 889 n = length(ticks);
wolffd@0 890 tend = num2str(ticks(n));
wolffd@0 891 c = strncmp(labs(1),t1,length(labs(1))) & ...
wolffd@0 892 strncmp(labs(n),tend,length(labs(n)));
wolffd@0 893 end
wolffd@0 894
wolffd@0 895 function r = LocalAxesTightBoundingBox(axesR, a)
wolffd@0 896 r = [];
wolffd@0 897 atext = findall(a,'type','text','visible','on');
wolffd@0 898 if ~isempty(atext)
wolffd@0 899 set(atext,'units','points');
wolffd@0 900 res=LocalGetAsCell(atext,'extent');
wolffd@0 901 for n=1:length(atext)
wolffd@0 902 r = LocalUnionRect(r,res{n});
wolffd@0 903 end
wolffd@0 904 end
wolffd@0 905 if strcmp(get(a,'visible'),'on')
wolffd@0 906 r = LocalUnionRect(r,[0 0 axesR(3:4)]);
wolffd@0 907 oldunits = get(a,'fontunits');
wolffd@0 908 set(a,'fontunits','points');
wolffd@0 909 label = text(0,0,'','parent',a,...
wolffd@0 910 'units','points',...
wolffd@0 911 'fontsize',get(a,'fontsize'),...
wolffd@0 912 'fontname',get(a,'fontname'),...
wolffd@0 913 'fontweight',get(a,'fontweight'),...
wolffd@0 914 'fontangle',get(a,'fontangle'),...
wolffd@0 915 'visible','off');
wolffd@0 916 fs = get(a,'fontsize');
wolffd@0 917
wolffd@0 918 % handle y axis tick labels
wolffd@0 919 ry = [0 -fs/2 0 axesR(4)+fs];
wolffd@0 920 ylabs = get(a,'yticklabels');
wolffd@0 921 yticks = get(a,'ytick');
wolffd@0 922 maxw = 0;
wolffd@0 923 if ~isempty(ylabs)
wolffd@0 924 for n=1:size(ylabs,1)
wolffd@0 925 set(label,'string',ylabs(n,:));
wolffd@0 926 ext = get(label,'extent');
wolffd@0 927 maxw = max(maxw,ext(3));
wolffd@0 928 end
wolffd@0 929 if ~LocalLabelsMatchTicks(ylabs,yticks) & ...
wolffd@0 930 strcmp(get(a,'xaxislocation'),'bottom')
wolffd@0 931 ry(4) = ry(4) + 1.5*ext(4);
wolffd@0 932 end
wolffd@0 933 if strcmp(get(a,'yaxislocation'),'left')
wolffd@0 934 ry(1) = -(maxw+5);
wolffd@0 935 else
wolffd@0 936 ry(1) = axesR(3);
wolffd@0 937 end
wolffd@0 938 ry(3) = maxw+5;
wolffd@0 939 r = LocalUnionRect(r,ry);
wolffd@0 940 end
wolffd@0 941
wolffd@0 942 % handle x axis tick labels
wolffd@0 943 rx = [0 0 0 fs+5];
wolffd@0 944 xlabs = get(a,'xticklabels');
wolffd@0 945 xticks = get(a,'xtick');
wolffd@0 946 if ~isempty(xlabs)
wolffd@0 947 if strcmp(get(a,'xaxislocation'),'bottom')
wolffd@0 948 rx(2) = -(fs+5);
wolffd@0 949 if ~LocalLabelsMatchTicks(xlabs,xticks);
wolffd@0 950 rx(4) = rx(4) + 2*fs;
wolffd@0 951 rx(2) = rx(2) - 2*fs;
wolffd@0 952 end
wolffd@0 953 else
wolffd@0 954 rx(2) = axesR(4);
wolffd@0 955 % exponent is still below axes
wolffd@0 956 if ~LocalLabelsMatchTicks(xlabs,xticks);
wolffd@0 957 rx(4) = rx(4) + axesR(4) + 2*fs;
wolffd@0 958 rx(2) = -2*fs;
wolffd@0 959 end
wolffd@0 960 end
wolffd@0 961 set(label,'string',xlabs(1,:));
wolffd@0 962 ext1 = get(label,'extent');
wolffd@0 963 rx(1) = -ext1(3)/2;
wolffd@0 964 set(label,'string',xlabs(size(xlabs,1),:));
wolffd@0 965 ext2 = get(label,'extent');
wolffd@0 966 rx(3) = axesR(3) + (ext2(3) + ext1(3))/2;
wolffd@0 967 r = LocalUnionRect(r,rx);
wolffd@0 968 end
wolffd@0 969 set(a,'fontunits',oldunits);
wolffd@0 970 delete(label);
wolffd@0 971 end
wolffd@0 972
wolffd@0 973 function c = LocalManualAxesMode(old, allAxes, base)
wolffd@0 974 xs = ['X' base];
wolffd@0 975 ys = ['Y' base];
wolffd@0 976 zs = ['Z' base];
wolffd@0 977 oldXMode = LocalGetAsCell(allAxes,xs);
wolffd@0 978 oldYMode = LocalGetAsCell(allAxes,ys);
wolffd@0 979 oldZMode = LocalGetAsCell(allAxes,zs);
wolffd@0 980 old = LocalPushOldData(old, allAxes, {xs}, oldXMode);
wolffd@0 981 old = LocalPushOldData(old, allAxes, {ys}, oldYMode);
wolffd@0 982 old = LocalPushOldData(old, allAxes, {zs}, oldZMode);
wolffd@0 983 set(allAxes,xs,'manual');
wolffd@0 984 set(allAxes,ys,'manual');
wolffd@0 985 set(allAxes,zs,'manual');
wolffd@0 986 c = old;
wolffd@0 987
wolffd@0 988 function val = LocalCheckAuto(val, auto)
wolffd@0 989 if ischar(val) & strcmp(val,'auto')
wolffd@0 990 val = auto;
wolffd@0 991 end