xline
Draws a vertical line at a given x value across the axes.
Category: Graphics > Formatting and Annotation
Syntax
xline(xvalue)
Draws a vertical line at xvalue. A vector draws one line per element.
xline(xvalue, LineSpec)
Sets the line style and color, for example '--r'.
xline(xvalue, LineSpec, label)
Also attaches a text label to the line.
xl = xline(___)
Returns the line object.
Description
Unlike line, the line spans the whole height of the axes even when the limits change, because it is tied to a value and not to a pair of end points. It does not affect the automatic axis limits.
It is handy for marking a threshold, an event time or a mean. The horizontal counterpart is yline.
Input arguments
xvalue- Position or positions along the x-axis.
label- Text shown next to the line.
Output arguments
xl- Constant line object, class
matlab.graphics.chart.decoration.ConstantLine, with the propertiesValue,LabelandColor.
Example
Mark an event
t = 0:0.1:10;
plot(t, sin(t))
h = xline(5, '--r', 'event');
h.Value
h.Label
Output
ans = 5
ans = 'event'