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

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