Displaying random numbers as a graph

17 vues (au cours des 30 derniers jours)
Mustafa Vural
Mustafa Vural le 17 Oct 2020
Commenté : Star Strider le 18 Oct 2020
I am generating random numbers with the rejection sampling, like in this picture. How can I see my generated random numbers as points, like in this picture?
  1 commentaire
Adam Danz
Adam Danz le 18 Oct 2020
plot()
scatter()

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 18 Oct 2020
One approach is to use the inpolygon function:
x = linspace(0, 10);
y = exp(-(x-5).^2)*0.2;
r = rand(1000,2).*[10 0.25];
[in,on] = inpolygon(r(:,1),r(:,2), x, y);
figure
plot(x,y)
hold on
plot(r(:,1), r(:,2),'.r')
plot(r(in,1), r(in,2), '.g')
hold off
producing:
Experiment with it to get the result you want.
.
  6 commentaires
Mustafa Vural
Mustafa Vural le 18 Oct 2020
I understand now, thank you very much! I appreciate it!
Star Strider
Star Strider le 18 Oct 2020
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices 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!

Translated by