MATLAB Answers

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

3 views (last 30 days)
Jiyoon Kim
Jiyoon Kim on 14 Oct 2021
Commented: Jiyoon Kim on 14 Oct 2021
This is my code
N=[randi([1,5],1,2),randi([10,50],1,2),randi([100,500],1,2)];
t=[-10:0.01:10];
tau=2*pi/3
for i=1:length(N)
phi = exponential(N(i),t,tau);
subplot(3,1,i)
plot(t, phi,'b-')
end
% and here's my code for the functions
function phi = exponential(N,t,tau)
syms t
w=1;
for i = 1:length(tau)
T = tau(i)
f = (1)
do = (1/(2*pi)) * int(f,t,-T/2,T/2);
doz = double(do)
d0vec(i)=doz
end
for i=1:length(N)
for n=1:N(i)
fun = 1*exp(N*t*w*j);
dn = (1/(2*pi))*int(f*cos(n*pi*t),t,-T/2,T/2);
ddn = double(dn);
dnz(n) = ddn;
end
dnhar{i} = dnz;
end
for i=1:length(N)
ef = 0;
for n=1:N(i)
estf=((dnhar{i}(n))*exp(j*w*N*t));
ef = ef+estf
end
ftarray = ef+doz
end
phi = eval(ftarray);
end
I am supposed to calculate and graph the nth term of fourier exponential series.

Accepted Answer

KSSV
KSSV on 14 Oct 2021
Variable phi used in the plot is a symbolic variable.
1/3 - (310775629405771*exp(t*4i))/576460752303423488
You cannot plot that striaght away using plot. Read about subs, get tvalues substitute values in there convert them into number using double and then plot.
Read about subs, double.
Also have a look on ezplot, fplot.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!