Increases the number of grid lines where you want to, without adding more labels on the axis.
Updated 10 Mar 2017

View License

% You create a graph and you do "grid on", but you want more of those major
% grid lines at certain values of the axis, without these values getting
% labeled: This function makes it happen. Especially interesting when data
% is not a continous but a discrete set (like "years"), so that the command
% "grid minor" is not appropriate. Tested in MATLAB2010b and MATLAB2016a.
% (II) s must be a string: 'x', 'y' or 'z' (the desired axis)

% Example 1:
% After creating a graph and doing "grid on", we want more lines
% at certain values of the x-axis. We save all the x-values we want
% with a grid line in a matrix "X". We do:

% >>gridmore(X,'x');

% Example 2:
% We are going to make different graphs and we want the same grid on
% the x-axis in all of them. We do, e.g., for the first figure:

% >>plot(A,B);
% grid on
% [xlabels]=gridmore(X,'x');

% For the following figures, don't call the function again; use the
% output argument "xlabels":

% >>plot(C,D);
% grid on
% set(gca,'Xtick',X,'XTickLabel',xlabels)

% How does gridmore.m work?
% XTick, YTick and ZTick are the location of the tick marks and major
% grid lines for each axis. XTickLabel, YTickLabel and ZtickLabel are the
% labels for each tick mark. The function increases the number of ticks
% labeling new ticks with an empty label.

% Any bugs, inquiries or suggestions to the comment section. Please rate.

% Thank you!

% Enjoy

% gridmore.m is licensed under MathWorks' license of choice for File
% Exchange contributions

% gridmore.m (c) 2017, by Álvaro López de Quadros
% All rights reserved

% You should have received a copy of the license along with this
% work.

Cite As

Álvaro F. López de Quadros (2024). gridmore.m (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes

Removed Creative Commons License as demanded by The MATLAB Administration.

Typos fixed and revised wording. Tested in MATLAB2010b and 2016a. New and simpler input argument s. Now the function includes the call to "set" so you do not need to call it afterwards. A better second example. "USE AFTER GRID ON" explicitly stated.