Displaying random numbers as a graph

조회 수: 17 (최근 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?

채택된 답변

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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by