Error using "plot" : Data must be numeric, datetime, duration or an array convertible to double??

34 Ansichten (letzte 30 Tage)
Hi everyone. I wrote the following code but I get this error:
"error using plot: Data must be numeric, datetime, duration or an array convertible to double."
Kindly resolve this issue.
clear all
close all
clc
s=tf('s');
H = 1/(12*s+1);
Gp = 70/(50*s+1);
Gv=0.02/(4*s+1);
Gc = 0.0799;
Tsp = 1/s;
D = -0.01/s;
% Open loop transfer function:
GsHs = Gp*Gv*H;
sys = feedback(Gc*Gp*Gv,H);
stepinfo(sys)
t = 0:0.1:15;
[y,t] = step(sys);
e = 1-y; %this is E(s) due to Tsp(s) and D(s)
figure(1)
plot(t,e,'linewidth',2)
xlim([0,t(end)])
grid
title('error')
figure(2)
[y,t] = step(sys);
U = e.*Gc;
subplot(4,1,1);
plot(t,U,'linewidth',2);
grid
title('U(s)')
[y,t] = step(sys);
U0 = U.*Gv;
subplot(4,1,2);
step(U0);
grid
title('U0(s)')
[y,t] = step(sys);
T = (U0+D).*Gp;
subplot(4,1,3);
plot(t,T,'linewidth',2);
grid
title('T(s)')
[y,t] = step(sys);
Tm = T.*H;
subplot(4,1,4);
plot(t,Tm,'linewidth',2);
grid
title('Tm(s)')
  2 Kommentare
Mathieu NOE
Mathieu NOE am 31 Dez. 2020
hi
multiple errors because you attempt to plot a transfer function structure like here
Error in tmp (line 39)
plot(t,T,'linewidth',2);
what did you intend to plot from transfer function T ?
Muhammad Sanwal
Muhammad Sanwal am 1 Jan. 2021
Their step responses. That is why I also used the command [y,t]=step("transfer function").
However, if i ONLY use the step command and omit plot command, then i merely obtain graphs with straight lines (as in of the equatipn y=mx), which is not the correct answer.
The intermediate variables that i need to plot are indicated in the following block diagram:

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 1 Jan. 2021
Apparently, the error is that subplot attempts to plot a transfer function step response without evaluating it.
Try this instead:
[y,t] = step(sys);
T = (U0+D).*Gp;
[y1,t1] = step(T);
subplot(4,1,3);
plot(t1,y1,'linewidth',2);
grid
title('T(s)')
[y,t] = step(sys);
[y2,t2] = step(T.*H);
subplot(4,1,4);
plot(t2,y2,'linewidth',2);
grid
title('Tm(s)')
That ran without error.
You need to determine if it does what you want.
  4 Kommentare
Muhammad Sanwal
Muhammad Sanwal am 9 Jan. 2021
I'm getting the same plots, but I don't understand why the graph of U0(s) consists of so many lines. As in, why is it 'thick'?
Star Strider
Star Strider am 9 Jan. 2021
That is because both ‘U0.Numerator’ and ‘U0.Denominator’ are both (127x1) cell arrays.
Taking a closer look at the first 5:
U0Num = U0.Numerator;
U0N_Detail = cell2mat(U0Num(1:5));
are:
U0N_Detail =
0 0.001598000000000
0 0.001596545200156
0 0.001593037273404
0 0.001588374882729
0 0.001583104870235
and:
U0Den = U0.Denominator;
U0D_Detail = cell2mat(U0Den(1:5));
are:
U0D_Detail =
4 1
4 1
4 1
4 1
4 1
There are 127 of these transfer functions total, and so all 127 are plotted.
If you want different results, you will need to change your code to produce the results you want.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by