我想绘制一个使用楼梯的二进制输入,但数据并非从零开始。那么如何让剧情从零而不是从一开始?Matlab的楼梯图并非从原点开始
MATLAB代码:
a = [ 0 0 1 0 1 0 0 1 0 1 1 1 1 1 ];
stairs(a);
axis([0 14 -0.5 1.5 ]);
grid on;
我想绘制一个使用楼梯的二进制输入,但数据并非从零开始。那么如何让剧情从零而不是从一开始?Matlab的楼梯图并非从原点开始
MATLAB代码:
a = [ 0 0 1 0 1 0 0 1 0 1 1 1 1 1 ];
stairs(a);
axis([0 14 -0.5 1.5 ]);
grid on;
您的数据在x轴启动您应该添加的X向量,以澄清。
y = round(rand(1,10)); %binary vector
x = [0:length(y)-1]; %[0,1,2,3,4....]
stairs(x,y);
axis([0,10,-0.5,1.5])
以看看帮助的plot command:
情节(Y)创建Y中的数据的2-d线图对的 每个值的索引。
If Y is a vector, then the x-axis scale ranges from 1 to length(Y). If Y is a matrix, then the plot function plots the columns of Y versus their row number. The x-axis scale ranges from 1 to the
在Y.行数
If Y is complex, then the plot function plots the imaginary part of Y versus the real part of Y, such that plot(Y) is equivalent to
图(实(Y),IMAG(Y))。
要绘制从零开始: 载体:情节(0:长度(Y) - 1,y)的 矩阵:情节(0:大小(M,1) - 1,M)
这同样适用于楼梯,从0开始的简单方法是将x轴添加到您的图中,方便如下:
>> stairs(0:length(a)-1,a),axis([0 14 -0.5 1.5 ]);grid on;