Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a system of equations, about 3 equations, that I need to plot that are dependent on 2 variables, R and z. But one of the equations is R={constant value}. Here's the code:

R = 0:.1:500;
z = 5./R;
z2 = 40./R;
z3 = 20
plot(R, z, R, z2, R, y3)

...I don't really know how to get z3 to show up as a vertical line. Any ideas?

share|cite|improve this question
y3 is not defined – Jonas Stein Feb 19 '15 at 22:54
up vote 3 down vote accepted

z3 not showing up is because it has different size with R. In plot command two vectors must share the same length.

A simple solution is:

R = 0.1:.1:500;
z = 5./R;
z2 = 40./R;
z3 = 20;
plot(R, z, R, z2)
hold on;
plot([z3 z3], [min([z(:);z2(:)]) max([z(:);z2(:)])]);


Notice here 0 is excluded for otherwise max will give an Inf.

share|cite|improve this answer

There is an excellent answer over on repeated below for convenience. (Please go there an up vote the original answer) ---

There exist an undocumented function graph2d.constantline:

plot(-2:5, (-2:5).^2-1)
%# vertical line
hx = graph2d.constantline(0, 'LineStyle',':', 'Color',[.7 .7 .7]);
%# horizontal line
hy = graph2d.constantline(0, 'Color',[.7 .7 .7]);
share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.