MATLAB Answers

ocsse
0

why i'm getting this error?

Asked by ocsse
on 26 Mar 2018
Latest activity Answered by Prajith Chilummula on 5 Apr 2018
why i'm getting Vectors must be the same length? for an and bn. can someone explain the error also? i always make this mistake
samples = 500;
T = 5;
f0 = 1/T;
t = 0:(1/(samples*f0)):T; % 5 cycles
s = exp((10 - t) / 2);
n = 1:3;
N = 5;
s = repmat(s, [1 N]);
t = 0:(1/(samples*f0)):N*T;
figure()
hold on
plot(t, s)
grid on
a0 = (1/T) * sum(s);
an = (2/T) * s * cos(2*pi*f0*n*t);
bn = (2/T) * s * sin(2*pi*f0*n*t);
thanks

  1 Comment

KSSV
on 26 Mar 2018
s = s(1:length(t)) ;

Sign in to comment.

1 Answer

Answer by Prajith Chilummula on 5 Apr 2018

Hi ocsse,
The line below produces a vector of size 501.
t = 0:(1/(samples*f0)):T;
repmat repeats the 1X501 matrix 5 times along the row making it 1X2505 size vector.So s has 1X2505 dimension.
s = repmat(s, [1 N]);
The line below produces a vector of dimension 1X2501.
t = 0:(1/(samples*f0)):N*T;
So there is mismatch in sizes of s and t.Therefore you get the error mentioned.

  0 Comments

Sign in to comment.