@@ -4,6 +4,7 @@ function savePlots(figures, location, options)
4
4
arguments
5
5
figures (1 , : ) matlab.ui.Figure
6
6
location (1 , 1 ) string = " results"
7
+ options.Resolution (1 , 1 ) double = 300
7
8
options.ColonReplacement (1 , 1 ) string = " "
8
9
options.DotReplacement (1 , 1 ) string = " _"
9
10
options.SlashReplacement (1 , 1 ) string = " _"
@@ -21,22 +22,21 @@ function savePlots(figures, location, options)
21
22
22
23
mustBeFolder(location );
23
24
24
- for f = figures
25
+ figures = figures(isvalid( figures ));
25
26
26
- if isvalid( f )
27
+ for f = figures
27
28
28
- name = replace(f .Name , [" :" , " ." , " /" , " \" , " "" " ], [options .ColonReplacement , options .DotReplacement , options .SlashReplacement , options .SlashReplacement , options .QuoteReplacement ]);
29
- name = fullfile(location , name );
29
+ name = replace(f .Name , [" :" , " ." , " /" , " \" , " "" " ], [options .ColonReplacement , options .DotReplacement , options .SlashReplacement , options .SlashReplacement , options .QuoteReplacement ]);
30
+ name = fullfile(location , name );
30
31
31
- exportgraphics(f , fullfile(name + " .png" ), Resolution = 300 );
32
+ exportgraphics(f , fullfile(name + " .png" ), Resolution = options . Resolution );
32
33
33
- if options .SaveAsFig
34
+ if options .SaveAsFig
34
35
35
- try
36
- savefig(f , name );
37
- catch exception
38
- warning(" Could not save figure "" %s"" :\n%s" , f .Name , exception .message );
39
- end
36
+ try
37
+ savefig(f , name );
38
+ catch exception
39
+ warning(" Could not save figure "" %s"" :\n%s" , f .Name , exception .message );
40
40
end
41
41
end
42
42
end
0 commit comments