function discreteplot( arg, func, req_axis); % FUNCTION: discreteplot % % SYNOPSIS: discreteplot( X, Y [, REQAXIS]); % % DESCRIPTION: discreteplot plots the sequence Y % as a function of vector X with % vertical lines from the abscissa to the % function value point. REQAXIS is an axis % vector for the user who does not want the % defaults (see documentation for axis or enter % help axis in the command window to see the % format of the axis vector). Dotted lines % linearly interpolate the graph envelope unless % there are more than 100 lines. % % EXAMPLE: figure, subplot(2,1,1), % t = 0:.05:1; % discreteplot(t,sin(t)); % subplot(2,1,2), % t = 0:.05:5; % discreteplot(t,sin(t)); % % % AUTHOR: Neil Getz % DATE: 5-13-92 % % COPYRIGHT 1992, Neil Getz % if (nargin<2 | nargin>3) help discreteplot; return; end if ( length(arg) ~= length(func)), error('Argument lengths must be equal.'); return; end ENVMAX = 100; % largest number of data points for which the envelope is % plotted. % Set coordinates of graph extremes if these have not been specified % as arguments. if (nargin==2), ylow = 1.1*min([0 min(func) ]); yhigh = 1.1*max([0 max(func) ]); axis([ min(arg) max(arg) ylow yhigh ]); elseif (nargin == 3) axis( req_axis ); end % Plot the function envelope if the length of arg is not too long. if (length(arg) < ENVMAX+1), plot(arg,func,'r:'); else % otherwise just plot function value points. plot(arg,func,'r.'); end; % Find out the actual graph extreme coordinates used. v = axis; % Gets axis values and frees axes. % Draw a horizontal line at func = 0. % Draw vertical perpendiculars from the zero line to the data points. ra = row(arg); X = [v(1), ra; v(2), ra]; Y = [0, zeros(size(ra)); 0, row(func)]; hold on, plot(X,Y,'-r'); hold off;