How do I use the plot function if I have to plot along the (y = constant) or (x=constant)?

2 views (last 30 days)
I am stuck in a very basic problem but I need help.I want to keep 'x coordinate' constant and plot for y(the values for y theoretically should vary from positive infinity to negative infinity). What would be the procedure if we want to do the same for 'y' i.e 'y coordinate'as constant and varying x from positive infinity to negative infinity.

Answers (1)

Walter Roberson
Walter Roberson on 13 Sep 2017
yL = ylimit();
plot([constant_x, constant_x], YL);
and
xL = xlimit();
plot(xL, [constant_y, constant_y]);
This code draws between the current plot limits, since you cannot draw infinitely. The distinction of plot limits matters if you are planning to allow the user to pan (scroll) areas that are not currently visible: the code above does not by itself create an effectively infinite line segment that should be drawn no matter how far the user pans.
  1 Comment
Stephen23
Stephen23 on 13 Sep 2017
Edited: Stephen23 on 13 Sep 2017
Undocumented, but this draws an "infinite" line:
fgh = figure();
axh = axes('Parent',fgh);
lnh = plot(axh,[1,1],[0,1]);
fun = @(~,evt)set(lnh,'YData',get(evt,'NewValue'));
addlistener(axh, 'YLim', 'PostSet',fun);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!