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

조회 수: 35 (최근 30일)
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
Mathieu NOE
Mathieu NOE 2020년 12월 31일
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 2021년 1월 1일
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:

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2021년 1월 1일
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
Muhammad Sanwal
Muhammad Sanwal 2021년 1월 9일
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 2021년 1월 9일
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개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by