Displaying random numbers as a graph

22 ビュー (過去 30 日間)
Mustafa Vural
Mustafa Vural 2020 年 10 月 17 日
コメント済み: Star Strider 2020 年 10 月 18 日
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 件のコメント
Adam Danz
Adam Danz 2020 年 10 月 18 日
plot()
scatter()

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2020 年 10 月 18 日
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 件のコメント
Mustafa Vural
Mustafa Vural 2020 年 10 月 18 日
I understand now, thank you very much! I appreciate it!
Star Strider
Star Strider 2020 年 10 月 18 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by