MATLAB Answers


How to randomly divide an M by M region into n sub regions

Asked by Shamsuddeen Abdullahi on 20 Apr 2019
Latest activity Edited by Image Analyst
on 20 Apr 2019
I what to randomly divide a sqaure region (20 by 20) into 3 portions (not necessary square in shape).
Then randomly deploy points in the 3 regions.
I tried the code below but not getting what i want. I need random divisions (different shapes e.g one portion can be a trapezoid and so on)
for i=1:1:m;
b(i)=(0.25 +(0.25).*rand).*m;
c(i)=(0.5 +(0.25).*rand).*m;
plot (n, '+r')
hold on
plot (b, 'ok')
hold on
plot (c, 'vg')
hold off
Please help
The above code gives divisions along horizontal lines
figure 1.
I need something like the above figure 1.


So like one portion might be inside a lopsided pentagon and the next could be out to an ellipse around it, and the third would be the rest?

Sign in to comment.

1 Answer

Answer by Image Analyst
on 20 Apr 2019
Edited by Image Analyst
on 20 Apr 2019

Try voronoi() if you want random points, or superpixels() if you have an image and want some sort of decision-based boundaries.


Sign in to comment.