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

3 views (last 30 days)
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 Comments
Cris LaPierre
Cris LaPierre on 18 Aug 2021
Thanks. You can accept your own answer, and by so doing, indicate to others that this question has a solution.

Sign in to comment.

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 18 Aug 2021
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.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!