MATLAB Answers

sigma deletes the axis grid

3 ビュー (過去 30 日間)
Giuseppe Naselli
Giuseppe Naselli 2019 年 7 月 17 日
編集済み: Adam Danz 2019 年 7 月 19 日
Hi All,
my code is below
myFigure=figure; % create a figure
ax1 = subplot(231, 'Parent', myFigure,'UserData','my_stuff','nextplot', 'add','XGrid','on','YGrid','on'); % create axix and set grid on in x and y
sigma(ax1,mySystem); % plot
The 2nd line create an axis with grid on, but then with the 3rd line the grid disappears
I can reset the grid back on with a 4th line as
however, I was wondering why "sigma" ignore my initial statement in subplot ('XGrid','on','YGrid','on')
Is there a setting in sigma/subplot that I can use?

回答 (1 件)

Adam Danz
Adam Danz 2019 年 7 月 17 日
編集済み: Adam Danz 2019 年 7 月 19 日
Short answer: You need to add the grid after calling sigma().
Long answer:
Assuming you're using the DynamicSystem method (toolbox \ control \ ctrlanalysis \ @DynamicSystem \ sigma.m), sigma() calls the helper function sigmaplot() which calls ltiplot() which does the plotting.
If "hold on" was not called prior to calling sigma(), the axes are cleared using cla() in ltiplot() as shown below.
% Clear and reset axes if new plot
if NewPlot
% Notify the live editor of newplot;
% Clear any existing response plot upfront (otherwise style
% settings below get erased by CLA in respplot/check_hold)
if ~isempty(h)
cla(h.AxesGrid,handle(ax)) % speed optimization
If "hold on" was called prior to calling sigma(), ltiplot() changes a bunch of axes properties. Listed below are the default PlotOptions created in ltiplot() and the changes made to the axis properties.
PlotOptions =
FreqUnits: 'auto'
FreqScale: 'log'
MagUnits: 'dB'
MagScale: 'linear'
IOGrouping: 'none'
InputLabels: [1×1 struct]
OutputLabels: [1×1 struct]
InputVisible: {'on'}
OutputVisible: {'on'}
Title: [1×1 struct]
XLabel: [1×1 struct]
YLabel: [1×1 struct]
TickLabel: [1×1 struct]
Grid: 'off' % <-----
GridColor: [0.15 0.15 0.15]
XLim: {[1 10]}
YLim: {[1 10]}
XLimMode: {'auto'}
YLimMode: {'auto'}
'XGrid', PlotOptions.Grid,... % <-----
'YGrid', PlotOptions.Grid,... % <-----
'XColor', PlotOptions.TickLabel.Color,...
'YColor', PlotOptions.TickLabel.Color,...
'FontSize', PlotOptions.TickLabel.FontSize,...
'FontWeight', PlotOptions.TickLabel.FontWeight,...
'FontAngle', PlotOptions.TickLabel.FontAngle,...
'Selected', 'off')
So, whether you hold your axes or not, the grids will be cleared. As you've discovered, you can add them back in after calling sigma().

Community Treasure Hunt

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

Start Hunting!

Translated by