BodePlot: Plotting straight lines on the Mag and Phase plots. Can access the phase plot, to do so, but not the mag plot

Hi there
I was customising the standard MATLAB Bode plot to make the gridlines, major and minor bold,
change the x and y label size and bold them and also customise the axis.
Then I tried to plot the straight line approximation, but I can only seem to access the phase plot, and not the magnitude plot.
For the two axes, ax(1) and ax(2), I have called them mag_ax and phase_ax.
I can access the other properties fine, but when I tries to add the lines, my code doesn’t recognise the mag_ax.
Any advice greatly appreciated

close all

s = tf(‘s’);

G_1 = tf(1/(0.1*s + 1));

figure(‘WindowState’,’maximized’);

gg = bodeplot(G_1);

title(‘Bode plot of $frac{1}{0.1s+1}$’,…
‘Interpreter’,’latex’,’FontSize’,18,’FontWeight’,’bold’);

gg.Responses.Color = "blue";
gg.Responses.LineWidth = 2;
gg.XLabel.FontWeight = "bold";

% Get the handles of the axes
ax = findobj(gcf,’type’,’axes’);
mag_ax = ax(1);
phase_ax = ax(2);

mag_ax.XLim = [0.1 1000];
mag_ax.YLim= [-60 +60];

phase_ax.XLim = [0.1 1000];
phase_ax.YLim= [-90 +90];

phase_ax.YTick = (-90:45:90);

grid on
grid minor
phase_ax.GridLineWidth = 1;
mag_ax.GridLineWidth = 1;

phase_ax.MinorGridLineStyle = ‘-‘;
mag_ax.MinorGridLineStyle = ‘-‘;

phase_ax.MinorGridLineWidth = 0.75;
mag_ax.MinorGridLineWidth = 0.75;

phase_ax.MinorGridAlpha = 0.5;
mag_ax.MinorGridAlpha = 0.5;

phase_ax.GridLineWidth = 1;
mag_ax.GridLineWidth = 1;

phase_ax.GridAlpha = 1;
mag_ax.GridAlpha = 1;

mag_ax.YLabel.FontWeight = "bold";
mag_ax.YLabel.FontSize = 12;

phase_ax.YLabel.FontWeight = "bold";
phase_ax.YLabel.FontSize = 12;

for k = 1:length(phase_ax)
xticks(phase_ax(k), [0.1 1 10 100 1000]); % Set desired tick positions
end
for k = 1:length(phase_ax)
phase_ax(k).XTickLabel = arrayfun(@(x) sprintf(‘%.1f’, x), phase_ax(k).XTick, ‘UniformOutput’, false);
end

set(phase_ax,’fontweight’,’bold’)
set(mag_ax,’fontweight’,’bold’)

gg.Responses.Visible = ‘on’;
gg.Responses.Color = ‘blue’;

mag_ax.NextPlot = ‘add’;
line([0.1 10.0],[0 0],’linewidth’,2,’color’,’red’);
line([10.0 1000],[0 -40],’linewidth’,2,’color’,’red’);

phase_ax.NextPlot = ‘add’;
line([0.1 1.0],[0 0],’linewidth’,2,’color’,’red’);
line([1.0 100],[0 -90],’linewidth’,2,’color’,’red’);
line([100 1000],[-90 -90],’linewidth’,2,’color’,’red’);Hi there
I was customising the standard MATLAB Bode plot to make the gridlines, major and minor bold,
change the x and y label size and bold them and also customise the axis.
Then I tried to plot the straight line approximation, but I can only seem to access the phase plot, and not the magnitude plot.
For the two axes, ax(1) and ax(2), I have called them mag_ax and phase_ax.
I can access the other properties fine, but when I tries to add the lines, my code doesn’t recognise the mag_ax.
Any advice greatly appreciated

close all

s = tf(‘s’);

G_1 = tf(1/(0.1*s + 1));

figure(‘WindowState’,’maximized’);

gg = bodeplot(G_1);

title(‘Bode plot of $frac{1}{0.1s+1}$’,…
‘Interpreter’,’latex’,’FontSize’,18,’FontWeight’,’bold’);

gg.Responses.Color = "blue";
gg.Responses.LineWidth = 2;
gg.XLabel.FontWeight = "bold";

% Get the handles of the axes
ax = findobj(gcf,’type’,’axes’);
mag_ax = ax(1);
phase_ax = ax(2);

mag_ax.XLim = [0.1 1000];
mag_ax.YLim= [-60 +60];

phase_ax.XLim = [0.1 1000];
phase_ax.YLim= [-90 +90];

phase_ax.YTick = (-90:45:90);

grid on
grid minor
phase_ax.GridLineWidth = 1;
mag_ax.GridLineWidth = 1;

phase_ax.MinorGridLineStyle = ‘-‘;
mag_ax.MinorGridLineStyle = ‘-‘;

phase_ax.MinorGridLineWidth = 0.75;
mag_ax.MinorGridLineWidth = 0.75;

phase_ax.MinorGridAlpha = 0.5;
mag_ax.MinorGridAlpha = 0.5;

phase_ax.GridLineWidth = 1;
mag_ax.GridLineWidth = 1;

phase_ax.GridAlpha = 1;
mag_ax.GridAlpha = 1;

mag_ax.YLabel.FontWeight = "bold";
mag_ax.YLabel.FontSize = 12;

phase_ax.YLabel.FontWeight = "bold";
phase_ax.YLabel.FontSize = 12;

for k = 1:length(phase_ax)
xticks(phase_ax(k), [0.1 1 10 100 1000]); % Set desired tick positions
end
for k = 1:length(phase_ax)
phase_ax(k).XTickLabel = arrayfun(@(x) sprintf(‘%.1f’, x), phase_ax(k).XTick, ‘UniformOutput’, false);
end

set(phase_ax,’fontweight’,’bold’)
set(mag_ax,’fontweight’,’bold’)

gg.Responses.Visible = ‘on’;
gg.Responses.Color = ‘blue’;

mag_ax.NextPlot = ‘add’;
line([0.1 10.0],[0 0],’linewidth’,2,’color’,’red’);
line([10.0 1000],[0 -40],’linewidth’,2,’color’,’red’);

phase_ax.NextPlot = ‘add’;
line([0.1 1.0],[0 0],’linewidth’,2,’color’,’red’);
line([1.0 100],[0 -90],’linewidth’,2,’color’,’red’);
line([100 1000],[-90 -90],’linewidth’,2,’color’,’red’); Hi there
I was customising the standard MATLAB Bode plot to make the gridlines, major and minor bold,
change the x and y label size and bold them and also customise the axis.
Then I tried to plot the straight line approximation, but I can only seem to access the phase plot, and not the magnitude plot.
For the two axes, ax(1) and ax(2), I have called them mag_ax and phase_ax.
I can access the other properties fine, but when I tries to add the lines, my code doesn’t recognise the mag_ax.
Any advice greatly appreciated

close all

s = tf(‘s’);

G_1 = tf(1/(0.1*s + 1));

figure(‘WindowState’,’maximized’);

gg = bodeplot(G_1);

title(‘Bode plot of $frac{1}{0.1s+1}$’,…
‘Interpreter’,’latex’,’FontSize’,18,’FontWeight’,’bold’);

gg.Responses.Color = "blue";
gg.Responses.LineWidth = 2;
gg.XLabel.FontWeight = "bold";

% Get the handles of the axes
ax = findobj(gcf,’type’,’axes’);
mag_ax = ax(1);
phase_ax = ax(2);

mag_ax.XLim = [0.1 1000];
mag_ax.YLim= [-60 +60];

phase_ax.XLim = [0.1 1000];
phase_ax.YLim= [-90 +90];

phase_ax.YTick = (-90:45:90);

grid on
grid minor
phase_ax.GridLineWidth = 1;
mag_ax.GridLineWidth = 1;

phase_ax.MinorGridLineStyle = ‘-‘;
mag_ax.MinorGridLineStyle = ‘-‘;

phase_ax.MinorGridLineWidth = 0.75;
mag_ax.MinorGridLineWidth = 0.75;

phase_ax.MinorGridAlpha = 0.5;
mag_ax.MinorGridAlpha = 0.5;

phase_ax.GridLineWidth = 1;
mag_ax.GridLineWidth = 1;

phase_ax.GridAlpha = 1;
mag_ax.GridAlpha = 1;

mag_ax.YLabel.FontWeight = "bold";
mag_ax.YLabel.FontSize = 12;

phase_ax.YLabel.FontWeight = "bold";
phase_ax.YLabel.FontSize = 12;

for k = 1:length(phase_ax)
xticks(phase_ax(k), [0.1 1 10 100 1000]); % Set desired tick positions
end
for k = 1:length(phase_ax)
phase_ax(k).XTickLabel = arrayfun(@(x) sprintf(‘%.1f’, x), phase_ax(k).XTick, ‘UniformOutput’, false);
end

set(phase_ax,’fontweight’,’bold’)
set(mag_ax,’fontweight’,’bold’)

gg.Responses.Visible = ‘on’;
gg.Responses.Color = ‘blue’;

mag_ax.NextPlot = ‘add’;
line([0.1 10.0],[0 0],’linewidth’,2,’color’,’red’);
line([10.0 1000],[0 -40],’linewidth’,2,’color’,’red’);

phase_ax.NextPlot = ‘add’;
line([0.1 1.0],[0 0],’linewidth’,2,’color’,’red’);
line([1.0 100],[0 -90],’linewidth’,2,’color’,’red’);
line([100 1000],[-90 -90],’linewidth’,2,’color’,’red’); bodeplot, matlab MATLAB Answers — New Questions

​

Leave a Reply

Your email address will not be published. Required fields are marked *