ERROR Data must be numeric, datetime, duration or an array convertible to double.
Show older comments
Hi guys, I've been having an issue with trying to plot a function but I keep getting the error in the title. I've found some work arounds such a redefining t in section 3.4 with 't = 1:10' however that makes the output wrong. Any help would be appreciated.
% Clearing and preparing the workspace
clear; clc; close all;
load Data1A;
Fs = 44100;
y = noiseSound;
%soundsc(y,Fs);
T = 5;
numreps = 20;
%%A3.2
y_wave= ones(1,Fs/2);
y1 = ([-5*y_wave 6*y_wave]);
% repetitions of for the period
s = repmat(y1, ([1,numreps]));
%Making sure that an appropriate time domain vector t was generated for this waveform.Time vector goes from 0 to 20 seconds
t = linspace(0,numreps*T, numreps*Fs + 1);
t = t(1:end - 1);
x = 3 + 3.*t - t.^2;
%Saving this to the variable additive_noise
additive_noise = repmat(y,1,20);
plot(t,y)
xlabel('Time')
ylabel('Audio Signal')
%%A3.3
syms n t
w0=pi; n = 1:10;
a0 = (1/5)*int(3+3*t-t.^2,t,0,5);
an = (2/5)*int((3+3*t-t.^2)*((cos(2*w0*n*t))/5),t,0,5);
bn = (2/5)*int((3+3*t-t.^2)*((sin(2*w0*n*t))/5),t,0,5);
%%A3.4
n = 1:10;
f0 = 1/5;
x = a0 + (an.*cos(2*pi*n*5.*t) + bn.*sin(2*pi*n*5.*t));
syms n
FS1 = symsum(x, n, 1, 10);
FS1 = repmat(FS1, [1,numreps]);
hold on
plot(t,FS1)
title('Figure1 - A2.1')
xlabel('Time')
ylabel('Audio Signal')
legend('Fourier Series Approximation')
hold off
Answers (1)
KSSV
on 3 Sep 2017
1 vote
In section A3.3 you have defined t as a symbolic variable. You cannot plot symbolic variable. You need to transfer it into double using double.
5 Comments
KSSV
on 3 Sep 2017
Yes it is...because still t is a symbolic variable. You have not assigned any values to it. If t values are same as defined in section A3.2, you define it again before plotting or use some other variable as syms t instead of t
potplant
on 3 Sep 2017
suharsh tyagi
on 4 Nov 2017
Use the fplot function instead, to plot the symbolic functions.
lenin sanchez
on 13 Apr 2018
thanks,that worked
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!