1
votes

I want to plot two functions and have the X and Y axis having smaller intervals than what is being shown.

Here is the plot

enter image description here

and here is my code

x = linspace(-2,2,100);    

plot (x, atan(x)), grid on;

ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';

hold on 
plot(x, x-atan(x).*(1+x.^2))
hold off

The x-axis has intervals of 0.5, but the y-axis does not. Could someone please show me how to make the axis's have smaller intervals? I want to 0.1, 0.2, 0.3, and 0.4 between the 0 and 0.5 on the x-axis. Then do the same thing on the $y$-axis.

I'm looking through https://www.mathworks.com/help/matlab/getting-started-with-matlab.html right now, but haven't found how to do what I described above.

1

1 Answers

2
votes

You want to change the tick positions. This can be done in a few ways but programmatically:

ax.XTick = -1.5:0.1:1.5

This will change the values marked on the X-axis to be 0.1,0.2 etc. If you want to only use the smaller spacing on a particular part of the axis then you can set the tick values individually (eg [-1 -0.5 0 0.1 0.2 0.3])

Changing the Y-axis is identical but with YTick

The documentation for this is here