# Set limits in Matlab plot automatically [closed]

How can I automatically set the limits of my axis to be e.g. 5% bigger than all data contained in the plot? Of course I could calculate the total max/min values for all the stuff I plot but I would have to do this for each plot separately. Since Matlab somehow must know all min/max values (it computes a decent limit itself) I guess it must be easier to do this.

p=0.05;

Further refinement would be to make this into a function that accepts any figure handle and allows a different expansion in $x$ and $y$, but those should be straightforward.