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

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 个评论

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 ?
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:

请先登录,再进行评论。

 采纳的回答

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 个评论

Of course!
This code:
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);
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)')
U0 = U.*Gv;
subplot(4,1,2);
[y,t] = step(U0);
plot(t,y,'LineWidth',1)
grid
title('U0(s)')
[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)')
pos = get(gcf, 'Position');
set(gcf, 'Position',pos+[0 -500 0 500])
produces this figure:
Some slight changes were necessary in the plot calls (since that was the original problem), however the majority of it — and all the control system calculations — are the original code.
.
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'?
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.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by