2016-09-07 5 views
0

Ich versuche, eine Binäreingabe mit Treppen zu plotten, aber die Daten beginnen nicht von Null. Also, wie man die Handlung von Null statt von einem startet?Matlab Treppe Plot startet nicht vom Ursprung

Matlab-Code:

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; 

Antwort

0

Sie sollten den x-Vektor, hinzufügen, um zu klären, wo Sie Ihre Daten auf der x-Achse starten.

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]) 
0

einen Blick auf die Hilfe für den plot command einnehmen:

plot (Y) erzeugt ein 2-D-Liniendiagramm der Daten in Y gegenüber dem Index von jeder Wert.

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 

Anzahl der Zeilen in 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 

plot (real (Y), imag (y)).

von Null beginnen zu plotten: Vektoren: plot (0: Länge (y) - 1, y) Matrices: plot (0: Größe (M, 1) - 1, M)

Das Gleiche gilt für Treppen. Der einfache Weg, um bei 0 zu beginnen, besteht darin, die x-Achse zu Ihrem Plot hinzuzufügen:

>> stairs(0:length(a)-1,a),axis([0 14 -0.5 1.5 ]);grid on;