필터 지우기
필터 지우기

How to Generate a Given Shaped Cluster of Data Points?

조회 수: 9 (최근 30일)
Cynthia Dickerson
Cynthia Dickerson 2018년 8월 15일
답변: KSSV 2018년 8월 16일
Hi,
I am trying to generate some example graphs of data with irregular distribution shapes. I want a simple scatter plot of a data cluster that looks like a "C", a cluster that looks kind of like a squished jellybean, and a cluster that has tightly clustered points on the left-hand tail and disperse points on the right hand. Is there like a drawing tool where Matlab would randomly fill the space that I pre-selected? Is there a good way to randomly make these data clusters, or do I just need to define them by hand?
Thanks, Cyndi
  댓글 수: 1
Adam Danz
Adam Danz 2018년 8월 15일
Do you have the coordinates (x,y) that outline the shapes?

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2018년 8월 16일
I would download the required shape image from google....get the boundary of the shape and generate random points inside the shape. Check the below example.
I = imread('Letter_c.svg.png') ;
I = rgb2gray(I) ;
[y,x] = find(~I) ;
idx = boundary(x,y) ;
x = x(idx) ; y = y(idx) ;
% Generate random numbers
ax = min(x) ; bx = max(x) ;
ay = min(y) ; by = max(y) ;
N = 10000 ;
xx = (bx-ax).*rand(N,1) + ax;
yy = (by-ay).*rand(N,1) + ay;
% Get points inside the C shape
idx = inpolygon(xx,yy,x,y) ;
figure
hold on
plot(x,y,'b')
plot(xx(idx),yy(idx),'.r')

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by