How can I set the axes ticks to evenly spaced non-monotonically increasing axes vectors?

21 views (last 30 days)
I want to set the axes XTicks to evenly-spaced, non-monotonically increasing axes vectors. When I execute
x = linspace(-pi,pi-2*pi/100,100);
y = sin(3*x)./(3*x);
plot(x*180/pi,y);
axis tight
myTicks = get(gca, 'xtick');
myTicks(myTicks<0) = myTicks(myTicks<0) + 360;
set(gca, 'xtick', myTicks)
I obtain the result
??? Error using ==> set
Values must be monotonically increasing.
I want to be able to set the XTicks vector to a non-monotonic axis vector so that when I use GINPUT to read the pointer coordinates I do not need to keep track of the differences between the actual XTicks and the value that I want them to represent.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The ability to specify non-monotonically increasing vectors as XTicks is not available in MATLAB 7.2 (R2006a).
As a workaround, change the XTickLabels to the value that the XTicks are supposed to represent on the image. Since this will not modify the XTicks, it is necessary to modify the value returned by GINPUT to reflect the difference between the XTicks and the XTickLabels. The following is an example of this:
x = linspace(-pi,pi-2*pi/100,100);
y = sin(3*x)./(3*x);
plot(x*180/pi,y);
axis tight
myTicks = get(gca, 'xtick');
myTicks(myTicks<0) = myTicks(myTicks<0) + 360;
set(gca, 'xticklabel', myTicks)
[x_val,y_val] = ginput;
x_val(x_val<0) = x_val(x_val<0) + 360;

More Answers (0)

Products


Release

R2006a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!