Build M file DRAW_RECTANGLE.M.
where p generates the number of rectangles
function Draw_rectangle (p) t = 1;x = rand (1) *10;y = rand (1) *10;w = rand (1) *10;h = rand (1) *10;b =[x y w h];rectangle (' Posit Ion ', B) a{t} =b;flag =1;while flag ==1 x = rand (1) *10; y = rand (1) *10; w = rand (1) *10; h = rand (1) *10; b =[x y W h]; num = 0; For j = 1:t if ~rectint (b,a{j}) num = num +1; End End If num = = t on; Rectangle (' Position ', b) t = t+1; A{t} =b; End If T = = P break endend% t = 1;% flag =1%% when flag ==1% for i =1:p% x = rand (1) *10;% y = rand (1) *10;% w = rand (1) *10;% h = rand (1) *10;% b =[x y w h];%% rectangle (' posit Ion ', B)% a{i} =b;% end% num = 0;% for i = 1: (p-1)% for j = (i+1):p% if Rectint (a{ I},A{J})% break% else% num = num +1;% end% end% end% % if num = = (p-1) *p/2% for i = 1:p% Rectangle (' Position ', a{i})% end% flag = 0;% end% End
MATLAB randomly generates multiple rectangles that do not overlap