📄 exportfig.m
字号:
print(H, tfile2, args{:});
set(allNonText,{'Visible'},oldvis);
set(allAxes,{'Color'},oldc);
set(allAxes,{'XGrid'},oldaxg);
set(allAxes,{'YGrid'},oldayg);
set(allAxes,{'ZGrid'},oldazg);
%hack up the postscript file
fid1 = fopen(tfile,'w');
fid2 = fopen(tfile2,'r');
line = fgetl(fid2);
while ischar(line)
if strncmp(line,'%%Title',7)
fprintf(fid1,'%s\n',['%%Title: ', tfile]);
elseif (length(line) < 3)
fprintf(fid1,'%s\n',line);
elseif ~strcmp(line(end-2:end),' PR') & ...
~strcmp(line(end-1:end),' L')
fprintf(fid1,'%s\n',line);
end
line = fgetl(fid2);
end
fclose(fid1);
fclose(fid2);
delete(tfile2);
elseif ~opts.applystyle
drawnow;
print(H, filename, args{:});
end
warning(oldwarn);
catch
warning(oldwarn);
hadError = 1;
end
% Restore figure settings
if opts.applystyle
varargout{1} = old;
else
for n=1:length(old.objs)
if ~iscell(old.values{n}) & iscell(old.prop{n})
old.values{n} = {old.values{n}};
end
set(old.objs{n}, old.prop{n}, old.values{n});
end
end
if hadError
error(deblank(lasterr));
end
%
% Local Functions
%
function outData = LocalPushOldData(inData, objs, prop, values)
outData.objs = {objs, inData.objs{:}};
outData.prop = {prop, inData.prop{:}};
outData.values = {values, inData.values{:}};
function cellArray = LocalGetAsCell(fig,prop,allowemptycell);
cellArray = get(fig,prop);
if nargin < 3
allowemptycell = 0;
end
if ~iscell(cellArray) & (allowemptycell | ~isempty(cellArray))
cellArray = {cellArray};
end
function newArray = LocalScale(inArray, scale, minv, maxv)
n = length(inArray);
newArray = cell(n,1);
for k=1:n
newArray{k} = min(maxv,max(minv,scale*inArray{k}(1)));
end
function gray = LocalMapToGray1(color)
gray = color;
if ischar(color)
switch color(1)
case 'y'
color = [1 1 0];
case 'm'
color = [1 0 1];
case 'c'
color = [0 1 1];
case 'r'
color = [1 0 0];
case 'g'
color = [0 1 0];
case 'b'
color = [0 0 1];
case 'w'
color = [1 1 1];
case 'k'
color = [0 0 0];
end
end
if ~ischar(color)
gray = 0.30*color(1) + 0.59*color(2) + 0.11*color(3);
end
function newArray = LocalMapToGray(inArray);
n = length(inArray);
newArray = cell(n,1);
for k=1:n
color = inArray{k};
if ~isempty(color)
color = LocalMapToGray1(color);
end
if isempty(color) | ischar(color)
newArray{k} = color;
else
newArray{k} = [color color color];
end
end
function newArray = LocalMapColorToStyle(inArray);
inArray = LocalGetAsCell(inArray,'Color');
n = length(inArray);
newArray = cell(n,1);
styles = {'-','--',':','-.'};
uniques = [];
nstyles = length(styles);
for k=1:n
gray = LocalMapToGray1(inArray{k});
if isempty(gray) | ischar(gray) | gray < .05
newArray{k} = '-';
else
if ~isempty(uniques) & any(gray == uniques)
ind = find(gray==uniques);
else
uniques = [uniques gray];
ind = length(uniques);
end
newArray{k} = styles{mod(ind-1,nstyles)+1};
end
end
function newArray = LocalMapCData(inArray);
n = length(inArray);
newArray = cell(n,1);
for k=1:n
color = inArray{k};
if (ndims(color) == 3) & isa(color,'double')
gray = 0.30*color(:,:,1) + 0.59*color(:,:,2) + 0.11*color(:,:,3);
color(:,:,1) = gray;
color(:,:,2) = gray;
color(:,:,3) = gray;
end
newArray{k} = color;
end
function outData = LocalUpdateColors(inArray, prop, inData)
value = LocalGetAsCell(inArray,prop);
outData.objs = {inData.objs{:}, inArray};
outData.prop = {inData.prop{:}, {prop}};
outData.values = {inData.values{:}, value};
if (~isempty(value))
if strcmp(prop,'CData')
value = LocalMapCData(value);
else
value = LocalMapToGray(value);
end
set(inArray,{prop},value);
end
function bool = LocalIsPositiveScalar(value)
bool = isnumeric(value) & ...
prod(size(value)) == 1 & ...
value > 0;
function value = LocalToNum(value,auto)
if ischar(value)
if strcmp(value,'auto')
value = auto;
else
value = str2num(value);
end
end
%convert a struct to {field1,val1,field2,val2,...}
function c = LocalToCell(s)
f = fieldnames(s);
v = struct2cell(s);
opts = cell(2,length(f));
opts(1,:) = f;
opts(2,:) = v;
c = {opts{:}};
function c = LocalIsHG(obj,hgtype)
c = 0;
if (length(obj) == 1) & ishandle(obj)
c = strcmp(get(obj,'type'),hgtype);
end
function c = LocalHas3DPlot(a)
zticks = LocalGetAsCell(a,'ZTickLabel');
c = 0;
for k=1:length(zticks)
if ~isempty(zticks{k})
c = 1;
return;
end
end
function r = LocalUnionRect(r1,r2)
if isempty(r1)
r = r2;
elseif isempty(r2)
r = r1;
elseif max(r2(3:4)) > 0
left = min(r1(1),r2(1));
bot = min(r1(2),r2(2));
right = max(r1(1)+r1(3),r2(1)+r2(3));
top = max(r1(2)+r1(4),r2(2)+r2(4));
r = [left bot right-left top-bot];
else
r = r1;
end
function c = LocalLabelsMatchTicks(labs,ticks)
c = 0;
try
t1 = num2str(ticks(1));
n = length(ticks);
tend = num2str(ticks(n));
c = strncmp(labs(1),t1,length(labs(1))) & ...
strncmp(labs(n),tend,length(labs(n)));
end
function r = LocalAxesTightBoundingBox(axesR, a)
r = [];
atext = findall(a,'type','text','visible','on');
if ~isempty(atext)
set(atext,'units','points');
res=LocalGetAsCell(atext,'extent');
for n=1:length(atext)
r = LocalUnionRect(r,res{n});
end
end
if strcmp(get(a,'visible'),'on')
r = LocalUnionRect(r,[0 0 axesR(3:4)]);
oldunits = get(a,'fontunits');
set(a,'fontunits','points');
label = text(0,0,'','parent',a,...
'units','points',...
'fontsize',get(a,'fontsize'),...
'fontname',get(a,'fontname'),...
'fontweight',get(a,'fontweight'),...
'fontangle',get(a,'fontangle'),...
'visible','off');
fs = get(a,'fontsize');
% handle y axis tick labels
ry = [0 -fs/2 0 axesR(4)+fs];
ylabs = get(a,'yticklabels');
yticks = get(a,'ytick');
maxw = 0;
if ~isempty(ylabs)
for n=1:size(ylabs,1)
set(label,'string',ylabs(n,:));
ext = get(label,'extent');
maxw = max(maxw,ext(3));
end
if ~LocalLabelsMatchTicks(ylabs,yticks) & ...
strcmp(get(a,'xaxislocation'),'bottom')
ry(4) = ry(4) + 1.5*ext(4);
end
if strcmp(get(a,'yaxislocation'),'left')
ry(1) = -(maxw+5);
else
ry(1) = axesR(3);
end
ry(3) = maxw+5;
r = LocalUnionRect(r,ry);
end
% handle x axis tick labels
rx = [0 0 0 fs+5];
xlabs = get(a,'xticklabels');
xticks = get(a,'xtick');
if ~isempty(xlabs)
if strcmp(get(a,'xaxislocation'),'bottom')
rx(2) = -(fs+5);
if ~LocalLabelsMatchTicks(xlabs,xticks);
rx(4) = rx(4) + 2*fs;
rx(2) = rx(2) - 2*fs;
end
else
rx(2) = axesR(4);
% exponent is still below axes
if ~LocalLabelsMatchTicks(xlabs,xticks);
rx(4) = rx(4) + axesR(4) + 2*fs;
rx(2) = -2*fs;
end
end
set(label,'string',xlabs(1,:));
ext1 = get(label,'extent');
rx(1) = -ext1(3)/2;
set(label,'string',xlabs(size(xlabs,1),:));
ext2 = get(label,'extent');
rx(3) = axesR(3) + (ext2(3) + ext1(3))/2;
r = LocalUnionRect(r,rx);
end
set(a,'fontunits',oldunits);
delete(label);
end
function c = LocalManualAxesMode(old, allAxes, base)
xs = ['X' base];
ys = ['Y' base];
zs = ['Z' base];
oldXMode = LocalGetAsCell(allAxes,xs);
oldYMode = LocalGetAsCell(allAxes,ys);
oldZMode = LocalGetAsCell(allAxes,zs);
old = LocalPushOldData(old, allAxes, {xs}, oldXMode);
old = LocalPushOldData(old, allAxes, {ys}, oldYMode);
old = LocalPushOldData(old, allAxes, {zs}, oldZMode);
set(allAxes,xs,'manual');
set(allAxes,ys,'manual');
set(allAxes,zs,'manual');
c = old;
function val = LocalCheckAuto(val, auto)
if ischar(val) & strcmp(val,'auto')
val = auto;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -