📅  最后修改于: 2023-12-03 14:44:10.898000             🧑  作者: Mango
The stairs()
function in MATLAB is used to create staircase charts or step charts. In a staircase chart, data is represented by a series of steps rather than a continuous line. This can be helpful when displaying data that is discrete or when you want to emphasize changes in data from one step to another.
stairs(Y)
stairs(X,Y)
stairs(...,'PropertyName',PropertyValue,...)
h = stairs(...)
The stairs()
function creates a 2D staircase chart. The input arguments can be either a single vector or two vectors. If only one vector is provided, the x-axis values will be generated automatically as 1:n
, where n
is the length of the input vector. If two vectors are provided, they must be of the same length and will be used as the x-axis and y-axis values, respectively.
Additional optional arguments can be used to customize the appearance of the chart. These include properties such as line color, line style, and marker type.
The stairs()
function returns a handle to the chart object. This can be used to modify the chart after it has been created.
x = 0:pi/50:10*pi;
y = sin(x);
stairs(x,y,'LineWidth',1.5,'Color','#0072BD')
xlabel('x')
ylabel('y')
title('2D Stairs Chart of sin(x)')
grid on
In this example, we create a staircase chart of the sin(x)
function for x
between 0
and 10*pi
. We set the line width to 1.5
and the line color to a shade of blue using the hex color code #0072BD
. We also add labels to the x-axis and y-axis, a title to the chart, and turn on the grid.