I don't know why my plot is wrong?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sarah Sadeq
le 25 Sep 2016
Réponse apportée : Image Analyst
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?
0 commentaires
Réponse acceptée
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);
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Scatter Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!