1
x = 0:0.005:4;

r = 0.1.*randn(4 / 0.005 + 1, 1);

y = 2.5 * sin(2 * pi * f * x);

plot(x, y);
hold on;
plot(x, r + y);

I want to add the r noise to the y graph but it just creates a mess on picrel. What am I doing wrong?enter image description here

erzis
  • 29
  • 2
  • 3
    You've fallen prey to implicit broadcasting. Your `x` and thus `y` are *row* arrays, i.e. 1-by-N, whereas you've created `r` to be a column vector,its size is M-by-1. What happens afterwards is explained by the duplicate. Instead, use either `x = (0:0.005:4).';` or `r = 0.1.*randn(1, 4 / 0.005 + 1);`, i.e. either make `x` a column array or `r` a row array – Adriaan Oct 21 '22 at 13:40

0 Answers0