Why i am getting an empty plot?

1 view (last 30 days)
Salah
Salah on 8 Jan 2023
Commented: Voss on 9 Jan 2023
%% i have this 4x18 matrix, and i want to plot the function resulting from each coloumn vs the number of coloumn
N = [1.551e-5 0.0011 0.0011 0.0011 0.0011 0.0011 0.0011 0.0011 9.6105e-4 0.0011 0.0011 0.0011 0.0011 0.0011 0.0011 0.0011 0.0011 0.0011;
0.0062 0.0061 0.0061 0.0060 0.0061 0.0060 0.0062 0.0061 0.0061 0.0062 0.0063 0.0062 0.0061 0.0051 0.0051 0.0055 0.0062 0.0062;
1.849e-5 2.3555e-4 7.1714e-4 0.0010 9.6128e-4 1.353e-4 4.1244e-4 1.9515e-4 1.3432e-4 4.9407e-4 1.6306e-4 8.6313e-4 5.9316e-4 3.4377e-4 2.2194e-4 2.8530e-4 8.2608e-4 7.0808e-4;
0.005 0.0035 0.0069 0.006 0.0069 0.0029 0.0055 0.0030 0.0029 0.0055 0.0035 0.0059 0.0044 0.0045 0.0034 0.0032 0.0049 0.0067];
for i=1:18
Cc= N(1,i);
Cf= N(2,i);
Lc= N(3,i);
Lf= N(4,i);
R = 50;
DutyC=0.76;
Vo=500;
s=tf('s');
dp = 1-DutyC;
w1 = -Lc;
w2 = dp*R;
u1 = Lc*Cc*R;
u2 = Lc;
u3 = (dp^2)*R;
x1 = Lf*Cf*(Lc^2)*dp*R*Cc;
x2 = (Lf+Lc*dp*R-(dp^2)*R*Lf*Cf)*Lc*Cc+(Lc^2)*Lf*Cf*dp*R;
x3 = (Lf+Lc*dp*R-(dp^2)*R*Lf*Cf)*Lc+Lf*Cf*Lc*(dp^3)*(R^2);
x4 = (Lf+Lc*dp*R-(dp^2)*R*Lf*Cf)*(dp^2)*R-(dp^2)*R*Lc;
x5 = -(dp^4)*(R^2);
y1 = Lc*Cc*Lf*Cf;
y2 = Lc*Cc + Lc*Lf*Cf;
y3 = Lc+Lf+Lf*Cf*(dp^2)*R;
y4 = R*(dp^2);
Gvd = (Vo*(s*w1 + w2)*((s^4)*x1+(s^3)*x2+(s^2)*x3+s*x4+x5))/(dp*((s^2)*u1+s*u2+u3)*((s^3)*y1+(s^2)*y2+s*y3+y4));
w = logspace(-1,3,100);
H = freqresp(Gvd,w);
objective = -20*log(abs(H));
g = min(objective);
plot(i,g)
end

Accepted Answer

Voss
Voss on 8 Jan 2023
You get an empty plot because you are plotting one point at a time (g and i are scalars). A line with one point doesn't show up without a data marker. To get a non-empty plot, use a data marker, or (better) collect the values of g in a vector and plot them together after the loop:
g = zeros(1,18); % pre-allocate vector g
N = [1.551e-5 0.0011 0.0011 0.0011 0.0011 0.0011 0.0011 0.0011 9.6105e-4 0.0011 0.0011 0.0011 0.0011 0.0011 0.0011 0.0011 0.0011 0.0011;
0.0062 0.0061 0.0061 0.0060 0.0061 0.0060 0.0062 0.0061 0.0061 0.0062 0.0063 0.0062 0.0061 0.0051 0.0051 0.0055 0.0062 0.0062;
1.849e-5 2.3555e-4 7.1714e-4 0.0010 9.6128e-4 1.353e-4 4.1244e-4 1.9515e-4 1.3432e-4 4.9407e-4 1.6306e-4 8.6313e-4 5.9316e-4 3.4377e-4 2.2194e-4 2.8530e-4 8.2608e-4 7.0808e-4;
0.005 0.0035 0.0069 0.006 0.0069 0.0029 0.0055 0.0030 0.0029 0.0055 0.0035 0.0059 0.0044 0.0045 0.0034 0.0032 0.0049 0.0067];
for i=1:18
Cc= N(1,i);
Cf= N(2,i);
Lc= N(3,i);
Lf= N(4,i);
R = 50;
DutyC=0.76;
Vo=500;
s=tf('s');
dp = 1-DutyC;
w1 = -Lc;
w2 = dp*R;
u1 = Lc*Cc*R;
u2 = Lc;
u3 = (dp^2)*R;
x1 = Lf*Cf*(Lc^2)*dp*R*Cc;
x2 = (Lf+Lc*dp*R-(dp^2)*R*Lf*Cf)*Lc*Cc+(Lc^2)*Lf*Cf*dp*R;
x3 = (Lf+Lc*dp*R-(dp^2)*R*Lf*Cf)*Lc+Lf*Cf*Lc*(dp^3)*(R^2);
x4 = (Lf+Lc*dp*R-(dp^2)*R*Lf*Cf)*(dp^2)*R-(dp^2)*R*Lc;
x5 = -(dp^4)*(R^2);
y1 = Lc*Cc*Lf*Cf;
y2 = Lc*Cc + Lc*Lf*Cf;
y3 = Lc+Lf+Lf*Cf*(dp^2)*R;
y4 = R*(dp^2);
Gvd = (Vo*(s*w1 + w2)*((s^4)*x1+(s^3)*x2+(s^2)*x3+s*x4+x5))/(dp*((s^2)*u1+s*u2+u3)*((s^3)*y1+(s^2)*y2+s*y3+y4));
w = logspace(-1,3,100);
H = freqresp(Gvd,w);
objective = -20*log(abs(H));
g(i) = min(objective); % store the result as the i-th element of the vector g
% plot(i,g)
end
plot(g) % or plot(1:18,g)
  2 Comments
Salah
Salah on 8 Jan 2023
Thanks a lot Voss, much appreciated.

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!