Search code examples
matlabaxes

Placing ticks in the middle of each grid in matlab


I am trying to create a figure with axes on matlab. But I want the ticks on the y-axis to be in the middle of each grid. How do I do that? An example is like this: enter image description here


Solution

  • As a workaround, you could turn on both major and minor gridlines, but set the major ones to the back color like this:

    ax = axes;
    grid(ax,'on');
    grid(ax,'Minor');
    set(ax,'GridColor',get(ax,'Color'))
    set(ax,'MinorGridLineStyle','-')
    set(ax,'TickLength',[0;0]);
    

    Which gives: enter image description here