-2
theta = linspace(0,2*pi,200); y = theta;x = 10;plot(x,y,'o');

When i write this i get the points but when i replace plot(x,y,'o') with plot(x,y) I should get a vertical line at x=4 but the graph comes empty..

  • 1
    Welcome to Stackoverflow. Please refer https://stackoverflow.com/help/how-to-ask . Please add more details of the issue that you are facing. – Nagama Inamdar Mar 26 '19 at 10:28
  • 2
    What about `plot([xStart xEnd], [yStart yEnd])`, if you just need a line between two points? – HansHirse Mar 26 '19 at 10:41
  • 3
    In R2018b onward, there's the function [`xline`](https://www.mathworks.com/help/matlab/ref/xline.html) for this. – Dev-iL Mar 26 '19 at 11:04
  • 1
    Possible duplicate of [Vertical refline in matlab?](https://stackoverflow.com/questions/17798093/vertical-refline-in-matlab) – Cris Luengo Mar 26 '19 at 12:56
  • (CASE 1)When I write the following code I get a graph with 10 points (in the y=x direction) The Code is *** x = linspace(0,10,10); y = x ; plot (x,y,'o'); *** (CASE 2)Now If I write only plot(x,y) in the above code instead of plot(x,y,'o') I get y=x line which is expected BUT Now in the following case (CASE 3)When I write the following code ***a= linspace (0,2*pi,20); y = a; x = 10; plot(x,y,'o'); *** The result is I get 20 points (Same as case 1) Now if I replace plot(x,y,'o') to plot (x,y) in the above code (in Case 3) I should get a line(Same as case 2)But I dont get it – Ajinkya Pokharkar Mar 26 '19 at 14:43
  • Possible duplicate of [How to draw horizontal and vertical lines in MATLAB?](https://stackoverflow.com/questions/28334660/how-to-draw-horizontal-and-vertical-lines-in-matlab) – SecretAgentMan Dec 17 '19 at 22:38

2 Answers2

2

You can use stem

x = 10;
y = 200;
stem(x,y,'Marker','none');

stem plot

Wolfie
  • 27,562
  • 7
  • 28
  • 55
1

From this answer: https://it.mathworks.com/matlabcentral/answers/2031-adding-vertical-line-to-plot

fig=figure; 
hax=axes; 
x=0:0.1:10; 
hold on 
plot(x,sin(x)) 
SP=1; %your point goes here 
line([SP SP],get(hax,'YLim'),'Color',[1 0 0])
enrico_ay
  • 76
  • 6