MATLAB: How to change the values on the axis of a graph

axisgraphs

I need to change both axes on a graph. Currently both are set to 0 10 20 30, but I need to change them to -20 -15 -10 -5 …. 35 40.
I have tried using axis([-20 40 -20 40]) but this leads to -20 -10 0 10 20 30 40. How can I change this to give intervals of 5 on the axis?
Thank you!

Best Answer

Try this:
figure
plot((0:30), rand(1,31))
xt = get(gca, 'XTick');
strc = compose('%d', -20:5:40);
xtv = linspace(min(xt), max(xt), numel(strc));
set(gca, 'XTick',xtv, 'XTickLabel',strc)