MATLAB: Minimum point of Graph

gradientgraphlineminimumplot

I have plotted a parabola like curve in the rough shape of (y=x^2). How am I able to draw plot a verical line from the minimum of the graph where the gradient is zero to the x axis and have this labbled as (Xminimum). Is it also possible to obtain an x value at which this value occurs on the graph too
Thanks

Best Answer

Use the islocalmin function:
x = -5:0.1:5;
y = x.^2;
idx = islocalmin(y);
figure(1)
hold on
plot(x,y)
plot(x(idx),y(idx),'*r')
legend('Curve','Local Min')
hold off
fprintf('Min located at %0.2f\n',x(idx))