function hh = lplot(varargin)
%LPLOT PLOT function that cycles through different line styles.
% LPLOT(X,Y) plots Y versus X just like the PLOT command but cycles
% through 12 different line styles instead of colors (4 line styles x 3
% line widths). The axes LineStyleOrder is set to '-|:|--|-.' and axes
% ColorOrder is set to [0 0 0]. Multiple data sets, accepted by PLOT,
% are allowed. e.g. LPLOT(X1, Y1, X2, Y2, ...) or LPLOT(X, [Y1, Y2, ...])
%
% H = LPLOT(...) returns a vector of line handles.
%
% Example:
% x = (0:0.1:10)';
%
% y1 = 1.2 * sin(x);
% y2 = 0.7 * cos(0.3 * x);
% y3 = 2 * sin(0.7 * x);
% y4 = y1 + y2;
% y5 = y1 + y3;
% y6 = y2 + y3;
% y7 = y1 - y2;
% y8 = y1 - y3;
% y9 = y3 - y2;
% y10 = y1 .* y2;
% y11 = y1 .* y3;
% y12 = y2 .* y3;
%
% h = lplot(x, [y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12]);
% legend(h, ...
% 'y1','y2','y3','y4','y5','y6','y7','y8','y9','y10','y11','y12', ...
% 'Location', 'EastOutside');
%
% See also PLOT, LINE.
% VERSIONS:
% v1.0 - first version
% v1.1 - added more linestyles
% v1.2 - added option to specify LineStyleOrder
% v1.3 - remove optional LineStyleOrder option. reset properties
% afterwards.
% v1.4 - allow all numeric input arguments accepted by PLOT. more line
% types (12).
%
% Copyright 2005-2010 The MathWorks, Inc.
if nargin < 1
error('Not enough inputs arguments');
end
% This is the prevent passing Param-Value pairs. If using Param-Value
% pairs, use PLOT instead.
if any(cellfun('isclass', varargin, 'char'))
error('All input arguments must be numeric matrices');
end
% prepare axes
axh = newplot;
nextplot = get(axh, 'NextPlot');
% get current LineStyleOrder and ColorOrder
LSCO = get(axh, {'LineStyleOrder', 'ColorOrder'});
% set LineStyleOrder and ColorOrder
set(axh, 'LineStyleOrder', '-|:|--|-.', ...
'ColorOrder', [0 0 0]);
% if the NextPlot property is 'replace', then PLOT will reset the
% LineStyleOrder and the ColorOrder properties.
% so change it to 'replacechildren'
if strcmpi(nextplot, 'replace')
set(axh, 'NextPlot', 'replacechildren');
end
% plot
h = plot(varargin{:});
% if there are more than 4 lines, change the thickness of the lines
if length(h) > 4
lw = get(h(1), 'linewidth');
set(h([5:12:end, 6:12:end, 7:12:end, 8:12:end]), 'linewidth', lw * 4);
set(h([9:12:end, 10:12:end, 11:12:end, 12:12:end]), 'linewidth', lw * 8);
end
% restore NextPlot, LineStyleOrder, and ColorOrder
set(axh, {'NextPlot','LineStyleOrder', 'ColorOrder'}, {nextplot,LSCO{:}});
if nargout == 1
hh = h;
end