% 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.
% (I) USE AFTER "GRID ON"
% (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:
% 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:
% grid on
% For the following figures, don't call the function again; use the
% output argument "xlabels":
% grid on
% 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!
% 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
Álvaro F. López de Quadros (2023). gridmore.m (https://www.mathworks.com/matlabcentral/fileexchange/61780-gridmore-m), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
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.