How do I plot a random number of rectangles using rectangle('Position', [x y w h])?

This is how I have tried. But it does not seem to work. As fast as I run the function, MATLAB gets in Busy-mode and never returns. What am I doing wrong?
function amount = draw_rectangle(b)
amount = b;
for j =1:b;
x = rand(1)*10;
y = rand(1)*10;
w = rand(1)*10;
h = rand(1)*10;
rectangle('Position', [x y w h])
hold on;
end
end

4 commentaires

what is the value of b?
Unless b is very big, there is no problem in your code
Ok! I do not really know how to manipulate b in MATLAB so that it returns a random value and therefore a random amount of rectangles. Could someone help me with that?
How are you using it then? If you don't know how to manipulate b that is.

Connectez-vous pour commenter.

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 26 Fév 2013
Modifié(e) : Azzi Abdelmalek le 26 Fév 2013
close
hold on;
for k=1:randi(100);
rectangle('Position', 10*rand(1,4))
end
hold off

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by