フィルターのクリア

I don't know why my plot is wrong?

1 回表示 (過去 30 日間)
Sarah Sadeq
Sarah Sadeq 2016 年 9 月 25 日
回答済み: Image Analyst 2016 年 9 月 25 日
Hi,
My question is the following:
Write a script noisify.m where you first create an x vector that has integer elements from 1 to 10, and then set a y vector equal to x. Plot this straight line. Now, add noise to the data points. Create a new y2 vector that stores the values of y plus or minus 0.25 (Hint: y2 is of the same length as y. Each element of y2 is either larger or smaller than the corresponding element of y by 0.25. Choose whether to be larger or smaller randomly) Plot the straight line and also these noisy points(using black stars for the marker points).
x=1:10;
y=x;
plot(x,y,'b');
hold on
a= 0.25* randi([0 1],1,10)- 0.25;
y2=y+a;
plot(x,y2,'k *')
i don't get why the plot is not similar to the one in my assignment?

採用された回答

Image Analyst
Image Analyst 2016 年 9 月 25 日
To get +/- 0.25, you need to have a range of 0.5. So change your code to be like this:
x = 1 : 10;
y = x;
plot(x, y, 'b');
hold on
additiveNoise = 0.5 * randi([0, 1], 1, length(y)) - 0.25;
y2 = y + additiveNoise;
plot(x, y2,'k*')
grid on;
xlabel('X', 'FontSize', 20);
ylabel('Y', 'FontSize', 20);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by