MATLAB Answers


plotting a vertical line in matlab?

Asked by Sarah
on 18 Apr 2012

Hey guys,

I am trying to plot a vertical line in matlab. i need to be able to change its thickness and its color. I will be plotting several vertical lines. I need to plot it at a specific point on the x-axis, and it needs to extend vertically in both directions.

Here is what I have so far:

xlabel('Time'); ylabel('Temp. (deg-C)'); grid on;
line([x(668) x(668)],[-3.2 -2.8]);
set(gca,'YLim',[-3.2 -2.8])

I dont know why, but my line doesn't show up. Any help would be much appreciated!

  1 Comment

on 18 Apr 2012

oh sorry, i almost forgot, here is the error notice:

??? Undefined function or method 'x' for input arguments of type


No products are associated with this question.

2 Answers

Answer by Geoff
on 18 Apr 2012

As the error says, you don't have a variable called x and so you can't ask for the 668th element.

You might mean this:

line([668 668],[-3.2 -2.8]);


Answer by Walter Roberson
on 18 Apr 2012

Your code

line([x(668) x(668)],[-3.2 -2.8]);

is fine. Just add appropriate options like 'LineWidth' and 'Color'.


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!