Error using "plot" : Data must be numeric, datetime, duration or an array convertible to double??
25 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Muhammad Sanwal
il 31 Dic 2020
Commentato: Star Strider
il 9 Gen 2021
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 Commenti
Mathieu NOE
il 31 Dic 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 ?
Risposta accettata
Star Strider
il 1 Gen 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 Commenti
Star Strider
il 9 Gen 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Line Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!