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

조회 수: 32 (최근 30일)
potplant
potplant 2017년 9월 3일
댓글: lenin sanchez 2018년 4월 13일
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
suharsh tyagi
suharsh tyagi 2017년 11월 4일
Use the fplot function instead, to plot the symbolic functions.

댓글을 달려면 로그인하십시오.

카테고리

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