MATLAB: How to set the axis in matlab to actual data min and max

axislabels

I'm plotting data and the x and y axis are setting the min and max to 0 and 300 but the actual data min and max is -6.1686 and -6.06 respectively. I've attached three images showing what I get, proving the min and max values and finally the expected axis labels.
Would really appreciate some help on how to solve this. Even if there is a manual way to set this and keep the generated image in position.

Best Answer

See if you can use the actual y min and max in ylim() to override the default y axis range:
yMin = min(y(:));
yMax = max(y(:));
ylim([yMin, yMax]);