-
Notifications
You must be signed in to change notification settings - Fork 0
/
fb_multi_fig_save.m
98 lines (78 loc) · 2.42 KB
/
fb_multi_fig_save.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function multi_fig_save(fighandle,save_dir,filename,formats,varargin)
%save in multiple formats in a single command
%
% multi_save(fighandle,save_dir,filename,formats)
%
%
%
%
%
renderer='painters';
res=300;
nparams=length(varargin);
if mod(nparams,2)>0
error('Parameters must be specified as parameter/value pairs');
end
for i=1:2:nparams
switch lower(varargin{i})
case 'renderer'
renderer=varargin{i+1};
case 'res'
res=varargin{i+1};
end
end
renderer=[ '-' renderer];
res=[ '-r' num2str(res)];
if nargin<4
formats='eps,fig,png';
end
try
if ~isempty(strfind(formats,'eps')) || strcmp(formats,'all')
print(fighandle,'-depsc2',renderer,fullfile(save_dir,[filename '.eps']));
end
if ~isempty(strfind(formats,'tiffn')) || strcmp(formats,'all')
print(fighandle,'-dtiffn',renderer,fullfile(save_dir,[filename '.tif']));
if exist('rsetwrite')>0
disp('Writing rset...')
rsetwrite(fullfile(save_dir,[filename '.tif']),fullfile(save_dir,[filename '.rset']));
response=[];
while isempty(response)
response=input('(K)eep the original .tiff or (d)elete? ','s');
switch lower(response(1))
case 'k'
break;
case 'd'
delete(fullfile(save_dir,[filename '.tif']));
otherwise
response=[];
end
end
end
end
%print(fighandle,'-dtiffn','-r300',fullfile(save_dir,[filename '.tif']));
if ~isempty(strfind(formats,'tiff')) || strcmp(formats,'all')
print(fighandle,'-dtiff',renderer,res,fullfile(save_dir,[filename '.tiff']));
end
if ~isempty(strfind(formats,'pdf')) || strcmp(formats,'all')
print(fighandle,'-dpdf',renderer,res,fullfile(save_dir,[filename '.pdf']));
end
if ~isempty(strfind(formats,'png')) || strcmp(formats,'all')
print(fighandle,'-dpng',renderer,res,fullfile(save_dir,[filename '.png']));
end
if ~isempty(strfind(formats,'fig')) || strcmp(formats,'all')
saveas(fighandle,fullfile(save_dir,[filename '.fig']));
end
catch
disp('Save did not work (running in terminal emulation?)...')
disp('Trying simple file formats...')
if ~isempty(strfind(formats,'eps')) || strcmp(formats,'all')
print(fighandle,'-depsc2',renderer,'-r100',fullfile(save_dir,[filename '.eps']));
end
if ~isempty(strfind(formats,'png')) || strcmp(formats,'all')
print(fighandle,'-dpng',renderer,'-r100',fullfile(save_dir,[filename '.png']));
end
if ~isempty(strfind(formats,'fig')) || strcmp(formats,'all')
saveas(fighandle,fullfile(save_dir,[filename '.fig']));
end
end
end