why i'm getting this error?

1 次查看(过去 30 天)
ocsse
ocsse 2018-3-26
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 个)

Prajith Chilummula
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.

类别

Help CenterFile Exchange 中查找有关 Matched Filter and Ambiguity Function 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by