-
Notifications
You must be signed in to change notification settings - Fork 7
/
print_fig.m
61 lines (53 loc) · 1.36 KB
/
print_fig.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
function [] = print_fig(fig, fname, params)
%PRINT_FIG This function is responsible for printing the figure to
% `fname` using `ptype` (default is `-dpng`)
%
% Based on work of Grammenos et al.: https://arxiv.org/abs/1907.08059
%
% Author Andreas Grammenos ([email protected])
%
% Last touched date 31/05/2020
%
% License: GPLv3
%
% check if we have a print flag (default is disabled)
if ~isfield(params, 'pflag')
pflag = 0;
else
pflag = params.pflag;
end
% check if we have a pdf print flag (default is enabled)
if ~isfield(params, 'pdf_print')
pdf_print = 1;
else
pdf_print = params.pdf_print;
end
% check if we have a fig print
if ~isfield(params, 'fig_print')
fig_print = 1;
else
fig_print = params.fig_print;
end
% check if we have a graph path set
if ~isfield(params, 'graph_path')
error('** ERR: Graph path must be present')
else
graph_path = params.graph_path;
end
% check if we are allowed to print
if pflag == 1
% generate the full path by concat the graph path + fname
p = strcat(graph_path, fname);
% check if we are saving in a .fig format
if fig_print == 1
savefig(fig, char(p));
end
% print normally (as an image)
print(fig, char(p), '-dpng');
% check if we have a global flag that we print to pdf as well
if pdf_print == 1
ptype = '-dpdf'; % change to '-dpdf' for pdf prints
print(fig, char(p), ptype);
end
end
end