Displaying random numbers as a graph
15 次查看(过去 30 天)
显示 更早的评论
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/383873/image.png)
采纳的回答
Star Strider
2020-10-18
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/383973/image.png)
Experiment with it to get the result you want.
.
6 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!