Error using plot. Data must be numeric, datetime, duration or an array convertible to double.
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
VBBV
am 15 Mär. 2023
Bearbeitet: VBBV
am 16 Mär. 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 Kommentar
VBBV
am 16 Mär. 2023
Bearbeitet: VBBV
am 16 Mär. 2023
The error suggests that you are trying to use symbolic variable for plot function. But plot function uses numeric arrays to graph, Further info how to use plot function can be found below link
if you want to plot symbolic expressions, try using fplot
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!