%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Illustration of use of the 'print' function to output a Matlab
% plot in the following formats
%
%    jpg    ->  JPEG image
%    png    ->  Portable network graphics
% 
% Images in these formats can be inserted into, e.g. Powerpoint
% presentations.
%
% Execution of this script should create the following files:
%    
%    tprint.jpg
%    tprint.png
% 
% Note that you can use the Linux 'imview' application to view 
% image files. E.g. after running this script, execute (in bash)
%
%    % imview tprint.jpg
% 
% (make sure that the command is invoked in the same directory in
% which the octave session is running).
% 
% See 'help print' for additional information.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Clear the figure window.
clf

% Generate a simple plot of sin(x), x = 0 .. 3 pi ...

% Define nx uniformly spaced x values, and compute y at those values.
nx = 1001;
x = linspace(0, 3*pi, nx);
y = sin(x);

% Make the plot.
plot(x, y);

% Now use 'print' to output the plot in various formats. 
% In each case the first argument to 'print' is a string
% giving the name of the image file that is to be created, while
% the second argument specifies the format of the image.

% 1) Output plot as JPEG image ...
print('tprint.jpg', '-djpeg');

% 2) Output plot as png image ...
print('tprint.png', '-dpng');
