Issues in plotting two graphs in the same plot with hold on function

Hi everybody, i have an issue in plotting the graph with hold on function. Here is the code:
clear all
close all
clc
s = tf('s');
%data
Gp = 4/(s*(-0.4*s-50));
Gs = 5;
Ga = 3;
Kd = 1;
Gf = 1/(Kd*Gs);
% requirement 8
zeta = (abs(log(0.08)))/(sqrt(pi^2+log(0.08)^2))
Tp_max = 1/(2*zeta*sqrt(1-zeta^2))
Sp_max = (2*zeta*sqrt(2+4*zeta^2+2*sqrt(1+8*zeta)))/(sqrt(1+8*zeta^2)+4*zeta^2-1)
% requirement 6
tr_wc = (1/(sqrt(1-zeta^2)))*(pi-acos(zeta))*(sqrt(sqrt(1+4*zeta^4)-2*zeta^2))
% requirement 7
ts_wc = (-log(0.05)/zeta)*(sqrt(sqrt(1+4*zeta^4)-2*zeta^2))
%From the summary
Kc = 100;
nu = 1;
% Design of the controller
Lin = Kc/(s^nu)*Gp*Ga*Gs*Gf
%Bode plot
% figure(2)
% bode(Lin)
% figure(3)
% [num_Lin,den_Lin]=tfdata(Lin,'v');
% nyquist1(num_Lin,den_Lin)
%plot of the forbidden region
figure(4)
myngridst(Tp_max,Sp_max)
zoom on, hold on
nichols(Lin)
I have problems in figure 4 (myngridst is a function provided by the teacher to plot the forbidden region in loop shaping design). In particular, when i run the same code but written few months ago, it works correctly; instead, if i write a new code or i modify the code written some months ago i have these problems:
Instead i should have something like this:
Thank you in advance.

6 个评论

As a best practice, always pair a hold on with a corresponding hold off.
We would need to know what your function myngridst is doing. On its own, there is no issue combining a nichols plot with another plot.
plot(linspace(1,20,720))
hold on
H = tf([-4 48 -18 250 600],[1 30 282 525 60]);
nichols(H)
hold off
In the screenshot matlab creates a new figure and makes the second plot in that figure, in the second you don't create the second figure and have both plots in the same figure.
Thanks. You can accept your own answer, and by so doing, indicate to others that this question has a solution.

请先登录,再进行评论。

 采纳的回答

In the screenshot matlab creates a new figure and makes the second plot in that figure, in the second you don't create the second figure and have both plots in the same figure.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by