This repository was archived by the owner on May 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathexport_figureToDisk.m
69 lines (55 loc) · 2.27 KB
/
export_figureToDisk.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
% Export figures to disk using some 3rd party writers
function export_figureToDisk(fig, fileNameOut, format, resolution, antiAliasLevel, options)
%% INPUT CHECKING
if ispc % Windows
splitFilePath = strsplit(fileNameOut, '\');
elseif isunix || ismac % LINUX/UNIX and MAC
splitFilePath = strsplit(fileNameOut, '/');
end
justTheFileName = splitFilePath{end}; % assuming that the filename is the last
% cell element
justThePath = [];
for i = 1 : length(splitFilePath) - 1
justThePath = fullfile(justThePath, splitFilePath{i});
end
disp(['output path = ', justThePath])
ifExists = exist(justThePath, 'dir')
% check that the folder exists
if exist(justThePath, 'dir') == 7
else
% modify path to the default folder
warning('Directory hassle, you initiated the function from incorrect folder (make more elegant later')
disp('Hassle continued.. Now the image is going to be exported to the default /figuresOut/ -folder')
try
justThePath = options.pathCode;
catch err
err
disp('hardCoded folder')
justThePath = '/home/petteri/Dropbox/MatlabCode/InDevelopment/2-PM_v2/twoPhotonVessels/figuresOut'
end
fileNameOut = fullfile(justThePath, justTheFileName);
if exist(justThePath, 'dir') == 7
else
warning('The default directory could not be found either? No figure exported')
justThePath
fileNameOut
return
end
end
%% DISK EXPORT
fileNameOut
% PNG
% Slightly nicer rendering than with the default Matlab PNG writer
if strcmp(format, 'png')
try
export_fig(fileNameOut, resolution, antiAliasLevel)
catch err
err
err.message
end
end
% SVG
% Supports alpha channels if you have transparency in your figure
if strcmp(format, 'svg')
%
end