سؤال

N=1000
n=1:N;
rng(1);
s1 = 0.2;
s2 = 0.8;
w1(n) = randn(N,1)*s1
w2 = randn(N,1)*s2
subplot(1,3,1)
y=(sin(n/50)+cos(n/200)-sin(n/100))
plot(n,y(n))
subplot(1,3,2)
y1(n) = y(n) + w1;
plot(n,y1(n))
subplot(1,3,3)
y2(n) = y(n)+w2 
plot(n,y2(n))

This code throws an error saying that the matrix dimensions should agree. Somebody please explain it.

هل كانت مفيدة؟

المحلول

w2 is 1000x1 while y(n) is 1x1000. You have to transpose w2:

y2(n) = y(n)+w2.' 
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top