Borrar filtros
Borrar filtros

Plotting a a constant line in a graph

66 visualizaciones (últimos 30 días)
Quantopic
Quantopic el 29 de Ag. de 2014
Respondida: Adam el 29 de Ag. de 2014
Hi all,
I need for plotting a constant line in a chart in which there is a time series X. So, given the time series X, texting in the command window the code:
plot(X)
I get the time series plot. How can I add to the graph a constant line k = 2? Thanks for help.

Respuesta aceptada

Iain
Iain el 29 de Ag. de 2014
plot(X,ones(size(X)) * k)

Más respuestas (1)

Adam
Adam el 29 de Ag. de 2014
plot( [X(1) X(end), [k k] )
would do the job visually if there isn't a reason you need to have a point for every value of your X time series.
Plotting e.g. 1000 points to define a horizontal line is unlikely to result in any kind of performance hit, but is a little un-necessary when 2 points would do just as well.
You can also use:
xlim = get( hAxes, 'Xlim' )
plot( xlim, [k k] )
if you simply want a horizontal line to span the full current x axis range irrespective of whether or not you have clipped the x limits to your X vector (though this is not advisable if you have zoomed in of course as then your horizontal line will be too short when you zoom out again).

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by