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
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 8 月 18 日
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.
Vinogiga Vanniyakulasingam
Vinogiga Vanniyakulasingam 2021 年 8 月 18 日
Thank you, i solved the problem.
Cris LaPierre
Cris LaPierre 2021 年 8 月 18 日
Share your solution as an answer below.
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 8 月 18 日
Cris LaPierre
Cris LaPierre 2021 年 8 月 18 日
Thanks. You can accept your own answer, and by so doing, indicate to others that this question has a solution.

サインインしてコメントする。

 採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2021 年 8 月 18 日

0 投票

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 ExchangeCreating, 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