DSPRelated.com
Free Books

Saving Plots to Disk: saveplot.m

Figure J.5: Compatibility matlab function for saving a plot to disk--Octave version.

 
function saveplot(filename,optargs)
% SAVEPLOT - Save current plot to disk in a PostScript file.
%            This version is compatible only with Octave.
%            In Matlab, just say 'print -deps[c] filename'.
%            *** MULTIPLOT MODE NOT SUPPORTED ***
%            (only get last plot)

if (nargin<2), optargs = ''; end;
% optargs to consider:
%   landscape
%   color
%   solid
%   "<fontname>" <fontsize>
%   lw <width> [default = 1.0]

gset terminal push

gset nomultiplot % can't set out terminal in multiplot mode
%gset terminal fig % in this output format, you can edit it!
cmd=['gset terminal postscript eps monochrome enhanced',...
     optargs];
eval(cmd);

disp(sprintf('Writing current plot to %s',filename));
cmd = sprintf('gset output \'%s\';',filename); eval(cmd);

replot
% remultiplot -- does not yet exist in gnuplot
closeplot

gset terminal pop

Figure J.6: Compatibility matlab function for saving a plot to disk--Matlab version.

 
function saveplot(filename)
% SAVEPLOT - Save current plot to disk in a PostScript file.
%            This version is compatible only with Matlab.

cmd = ['print -deps ',filename]; % for color, use '-depsc'
disp(cmd); eval(cmd);


Next Section:
Frequency Response Plots: plotfr.m
Previous Section:
Frequency Plots: freqplot.m