📄 stair_jw.m
字号:
function [xo,yo] = stair_jw(x,y,TEXT_COLOR)
%STAIRS Stairstep graph (bar graph without internal lines).
% Stairstep plots are useful for drawing time history plots of
% digital sampled-data systems.
% STAIRS(Y) draws a stairstep graph of the elements of vector Y.
% STAIRS(X,Y) draws a stairstep graph of the elements in vector Y at
% the locations specified in X. The X-values must be in
% ascending order and evenly spaced.
% [XX,YY] = STAIRS(X,Y) does not draw a graph, but returns vectors
% X and Y such that PLOT(XX,YY) is the stairstep graph.
%
% See also BAR, HIST.
% L. Shure, 12-22-88.
% Revised A.Grace and C.Thompson 8-22-90.
% Copyright (c) 1984-94 by The MathWorks, Inc.
% MODIFIED BY JMW 10/09/94 TO PLOT IN COLOR !
[n,nx] = size(x);
if isstr(x)
error('Input arguments must be numeric.')
end
if min(n,nx) > 1
error('Input arguments must be vectors.')
end
% Transpose x if row vector
if (n == 1 & nx > 1), x = x.'; end
[n,nx] = size(x);
if nargin==1, y=x; x=[0:n-1]'; end
if isstr(y)
error('Input arguments must be numeric.')
end
[n,nc] = size(y);
% Transpose x if row vector
if (n == 1 & nc > 1), y = y.'; [n,nc] = size(y); end
if (nx ~= nc & nx~= 1 & nc ~= 1)
error('Vectors must have the same number of columns')
end
y2 = [];
for i=1:nc
y1 = [ y(:,i).'; y(:,i).'];
y2 = [y2, y1(:)];
end
x2 = [];
for i=1:nx
x1 = [ x(:,i).'; x(:,i).'];
x2 = [x2, x1(:)];
end
% Remove extraneous first point
x2(1,:) = [];
% Uncomment next line if you want last point to be flat
%x2 = [x2; 2*x2(2*n-1,:)-x2(2*n-3,:)];
% ... and comment out the next line.
y2(2*n,:) = [];
if (nargout == 0)
plot(x2,y2,'color',TEXT_COLOR);
else
xo = x2;
yo = y2;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -