Cannot plot the fourier function "ERROR Data must be numeric, datetime, duration or an array convertible to double"
10 views (last 30 days)
Show older comments
Rex Cheang
on 25 Aug 2021
Answered: Cris LaPierre
on 25 Aug 2021
clear all
close all
%Sampling time
Ts=0.001;
t=0:Ts:2*pi;
%Timeaxis
TimeAxes_x = [0 10 0 0.5];
TimeAxes_y = [0 100 0 5000];
%Inverse fourier transform
syms w;
F2 = 1/(1+w^2);
f2 = ifourier(F2,t);
%F2w = 1/(1+t);
%Sampling frequency
fs=1/Ts;
w=(0:length(f2)-1)*fs/length(f2);
graph_subplot(1,211,w,abs(F2),TimeAxes_x,'t(s)','f2(w)','Frequency Doman of f2(t)');
Basically it just tells me that "ERROR Data must be numeric, datetime, duration or an array convertible to double" for that graph_subplot function. That function is basically a plot function. It mainly happens becasue of the w and abs(F2) in the functon. Can someone please help me with this?
1 Comment
Accepted Answer
Cris LaPierre
on 25 Aug 2021
F2 is a symbolic expression, not numeric. You need to either substitute in values for the symbolic variable w, or use a method for plotting that supports symbolic expressions (e.g. fplot).
%Sampling time
Ts=0.001;
t=0:Ts:2*pi;
%Inverse fourier transform
syms w;
F2 = 1/(1+w^2);
f2 = ifourier(F2,t);
%Sampling frequency
fs=1/Ts;
w2=(0:length(f2)-1)*fs/length(f2);
% substitute
plot(w2,abs(subs(F2,w,w2)))
% fplot
figure
fplot(F2)
0 Comments
More Answers (0)
See Also
Categories
Find more on Calculus 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!
