MATLAB: Minor grid-lines spacing issue

gridguiminor

I have created a GUI using GUIDE and have two checkboxes, where one toggles minor and the other toggles major gridlines. They both work by activating the appropriate lines, but the minor grid is exactly under the major. (So in effect only the major are visible.)
How can I fix this issue so that minor grid-lines appear in between the major as would be expected?
Note: I am using MATLAB 2015a
Major Grid Active
Minor Grid Active
Required Grid

Best Answer

Ben - how are you enabling and disabling the grid lines? If you are checkboxes are named checkbox1 and checkbox2 for the major and minor grid lines respectively, then the callbacks for both would be
function checkbox1_Callback(hObject, eventdata, handles)
if get(hObject,'Value') == 1
grid(handles.axes1,'on');
elseif get(handles.checkbox2,'Value') == 0
grid(handles.axes1,'off');
end
function checkbox2_Callback(hObject, eventdata, handles)
if get(hObject,'Value') == 1
grid(handles.axes1,'minor');
else
grid(handles.axes1,'minor');
if get(handles.checkbox1,'Value') == 0
grid(handles.axes1,'off');
end
end
We just need to add special cases to ensure that the major grid lines are turned off or left on depending upon whether the minor grid lines are off. See the attached code for an example.
Related Question