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

29 次查看(过去 30 天)
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 个)

KSSV
KSSV 2017-9-3
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 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by