MATLAB: Is it possible to add X and Y axis lines to a plot in MATLAB

MATLAB

I would like to have lines drawn at 'x=0' and 'y=0' on my plot.

Best Answer

This feature has been added in MATLAB 8.6(R2015b).
Please set 'XAxisLocation' and 'YAxisLocation' property to 'origin'. For details, please see the documentation.
If you are using a previous version, read the folllowing:
The ability to automatically draw lines at X = 0 and Y = 0 in an axes is not available in MATLAB. However, there is a simple way to manually add these lines to a plot.
For example, if you have the following plot
z = peaks(100);
plot(-49:50, z(:,26:5:50))
You can add the 0, 0 axis lines to it using the following code:
axh = gca; % use current axes
color = 'k'; % black, or [0 0 0]
linestyle = ':'; % dotted
line(get(axh,'XLim'), [0 0], 'Color', color, 'LineStyle', linestyle);
line([0 0], get(axh,'YLim'), 'Color', color, 'LineStyle', linestyle);