ERROR Data must be numeric, datetime, duration or an array convertible to double.

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

回答(1 个)

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 个评论

I get a new error saying
Error using symengine
DOUBLE cannot convert the input expression into a double array.
Error in sym/double (line 616)
Xstr = mupadmex('symobj::double', S.s, 0);
Error in mission (line 64)
double = double(t);
What I used is:
double = double(t);
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
I tried appending t to syms n before the FS1 function but that didn't work either. By defining it again do you simply mean just copy what I had in A3.2 into A3.4 like shown below? I'm not sure what you mean by I need to define it again, I'm not awfully good at this program.
%%A3.4
n = 1:10;
f0 = 1/5;
t = linspace(0,num_reps*T, num_reps*Fs + 1);
t = t(1:end - 1);
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, 10);
hold on
plot(t,FS1,'black')
title('Figure1 - A2.1')
xlabel('Time')
ylabel('Audio Signal')
legend('Fourier Series Approximation')
hold off
Use the fplot function instead, to plot the symbolic functions.

请先登录,再进行评论。

类别

Community Treasure Hunt

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

Start Hunting!

Translated by