How can I change the size of a circle patch?

10 vues (au cours des 30 derniers jours)
Alexandre Bernèche
Alexandre Bernèche le 20 Nov 2022
Hi,
I'm currently working on a GUI and I want to have filled circles of different sizes that can have their radius changed with a slider.
I used this code to create the filled circle and the function is called in the opening function of the GUI (I'm using GUIDE because I'm use to it):
function patch = fill_force(x,y,r)
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
patch = fill(xunit, yunit,'r','FaceAlpha',0.5,'EdgeColor','white');
hold off
I tried to change the size of the circle radius in the callBack function of the slider by using set for the XData and YData propreties and replacing them by new xunit and yunit. I don't get any error messages but my patch disappears on my GUI the moment I change my slider's position.
I'm guessing that I have to update multiple propreties but I don't know which one. Are there more efficient ways to update the patch?
The important part is that I want to update it and not deleting the current patch and making a new one since I have multiple patches.
Note: I don't have any toolbox with my liscence
Thank you in advance for any help someone can provide and please ask if you need more informations about my code
  3 commentaires
Les Beckham
Les Beckham le 21 Nov 2022
FYI: you shouldn't use patch as a variable name since it is a Matlab function.
Alexandre Bernèche
Alexandre Bernèche le 21 Nov 2022
Got it

Connectez-vous pour commenter.

Réponse acceptée

Voss
Voss le 20 Nov 2022
Modifié(e) : Voss le 20 Nov 2022
In the function y_update there is a mistake: you have cos when it should be sin. (This makes a line since x == y, rather than a cirle, and since the patch EdgeColor is white, you can't really see it.)
Changing that prevents the circle from disappearing, but the radius still does not change with changing the slider value, and that is because in the function slider1_Callback, the slider value is unused and instead a constant of 2.84*7.32 is used for the radius.
  2 commentaires
Alexandre Bernèche
Alexandre Bernèche le 21 Nov 2022
Thank you for the fast response!
It is now working correctly with the sin change!
Have a great day :)
Voss
Voss le 21 Nov 2022
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by