Plotting a a constant line in a graph
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuesta aceptada
Más respuestas (1)
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).
0 comentarios
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!