I don't know why my plot is wrong?

1 vue (au cours des 30 derniers jours)
Sarah Sadeq
Sarah Sadeq le 25 Sep 2016
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?

Réponse acceptée

Image Analyst
Image Analyst le 25 Sep 2016
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);

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by