Error using plot. Data must be numeric, datetime, duration or an array convertible to double.
2 views (last 30 days)
Show older comments
I have the following code I obtained from a function:
syms n t
A0 = 5/4;
An= 0;
Bn = (5*(-1)^n)/(n*pi);
T = 2;
Wo = pi;
Arm = 5;
for n=1:1:Arm
syms t
f(n,:) = sum ((A0) + (An * cos(n*t)) + (Bn * sin (n*t)));
t=linspace(0,5*T,1000);
subplot(2,1,1);
plot(t,subs(f(n,:), 't', t));
grid on
xlabel('\bfTIEMPO');
ylabel('\bfAMPLITUD');
title('\bfCOMPONENTE');
hold on
subplot(2,1,2);
plot(t, subs(sum(f), 't', t), 'r', 'Linewidth', 1.5);
xlabel('\bfTIEMPO');
ylabel('\bfAMPLITUD');
title('\bfSERIE DE FOURIER');
pause(1)
end
I got the Fourier coefficients and now I want to graph these results, but I'm getting the following error:
Error using plot
Data must be numeric, datetime, duration or an array convertible to double.
Error in Armonico_Fourier_Proyecto_parcial1 (line 16)
plot(t,subs(f(n,:), 't', t));
I'm really newbie into MATLAB, any help will be greatly appreaciated.
0 Comments
Answers (2)
VBBV
on 15 Mar 2023
Edited: VBBV
on 16 Mar 2023
% syms n
A0 = 5/4;
An= 0;
T = 2;
Wo = pi;
t=linspace(0,5*T,1000);
Arm = 5;
hold on
for n=1:1:Arm
Bn = (5*(-1)^n)/(n*pi);
f(n,:) = (An * cos(n*t)) + (Bn * sin (n*t));
figure(1)
plot(t,f(n,:));
grid on
xlabel('\bfTIEMPO');
ylabel('\bfAMPLITUD');
title('\bfCOMPONENTE');
end
figure(2)
plot(t, A0+sum(f), 'r', 'Linewidth', 1.5);
xlabel('\bfTIEMPO');
ylabel('\bfAMPLITUD');
title('\bfSERIE DE FOURIER');
1 Comment
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!