MATLAB: Could anyone tell me how to have equal spacing of selected numbers with respect to axis.

equal spacing

could anyone tell me how to have equal spacing of selected numbers with respect to axis with respect to the command line
set(gca, 'XTick', [0, 1, 2, 23,24]);
I want to have equal spacing between 0,1,2,23 and 24 with respect to x axis.

Best Answer

tx = XData;
mask = tx > 2.5;
tx(mask) = tx(mask) - 20;
plot(tx, YData);
xlim([0 4]);
set(gca, 'XTick', [0, 1, 2, 3,4]);
set(gca,'XTickLabel',num2str([0;1;2;23;24]))
dcm = datacursormode(gcf, 'DisplayStyle', 'datatip', 'UpdateFcn', @myupdatefcn, 'SnapToDataVertex', 'on');
with
function txt = myupdatefcn(src, event)
loc = event.Position;
x = loc(1);
y = loc(2);
if x > 2.5; x = x + 20; end
txt = {sprintf('x: %g', x), sprintf('y: %g', y)};
The assignment to dcm and the function are not needed if you do not care about what data cursor mode (tooltips) shows.