gridmore.m
% 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:
% >>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.
Citar como
Álvaro F. López de Quadros (2025). gridmore.m (https://www.mathworks.com/matlabcentral/fileexchange/61780-gridmore-m), MATLAB Central File Exchange. Recuperado .
Compatibilidad con la versión de MATLAB
Compatibilidad con las plataformas
Windows macOS LinuxCategorías
- MATLAB > Graphics > Formatting and Annotation > Axes Appearance > Limits, Ticks, and Grids > Grid Lines, Tick Values, and Labels >
Etiquetas
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Descubra Live Editor
Cree scripts con código, salida y texto formateado en un documento ejecutable.
Versión | Publicado | Notas de la versión | |
---|---|---|---|
2.1.0.0 | Removed Creative Commons License as demanded by The MATLAB Administration. |
||
2.0.0.0 | 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. |
||
1.0.0.0 |