# 2.3 Printing Line Styles

## Problem

Prior to MATLAB 4.0, solid lines were automatically converted to line styles when a noncolor printer was selected for graphical output. This does not happen automatically in MATLAB 4.x.

## Solution

You can print different line styles by cycling through an array of line styles and changing the LineStyle property of each solid line. After changing the line styles, print.m is called. This process is transparent to the user because the changes are not displayed in the Figure Window.

Below is an M-file named prtlines.m which automatically converts solid lines to line styles in all forms of graphical output.

```**********************************************************
function prtlines(a1,a2,a3,a4,a5)
% PRTLINES is a front-end to PRINT, which converts solid
% lines to various line styles for graphical output.  The
% change is transparent to the user.  Non-solid lines are
% not affected.
%
% PRTLINES is used in the same manner as PRINT.
% The default line styles are:
%
%     '. '
%     'o '
%     'x '
%     '+ '
%     '- '
%     '* '
%     ': '
%     '-.'
%     '-'
%
% The line style can be changed by editing the file and
% changing the 'styles'
% array.
% Create the array of line styles.
styles = [
'. '
'o '
'x '
'+ '
'- '
'* '
': '
'-.'
'-'
];
% Get the 'Children' of the Figure.
a = get(gcf,'children');
% Check the 'Children' of 'a'.  If they are solid lines,
% then change their 'LineStyle' property.
for j = 1:length(a)
l = sort(get(a(j),'children'));
X = 0;
for i = 1:length(l)
if strcmp( 'line', get(l(i), 'type' ))
if strcmp(get(l(i),'linestyle'),'-')
X = X + 1;
LINE = [LINE;l(i)];
SI =  rem(X,length(styles));
if SI == 0
end
end
end
end
end
% Construct the PRTCMD.
PRTCMD = 'print';
for x = 1:nargin
PRTCMD = [PRTCMD,' ',eval(['a',int2str(x)])];
end
% Discard the changes so that the Figure is not updated.