我想繪製一個使用樓梯的二進制輸入,但數據並非從零開始。那麼如何讓劇情從零而不是從一開始?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;