How can I change the size of a circle patch?

10 Ansichten (letzte 30 Tage)
Alexandre Bernèche
Alexandre Bernèche am 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 Kommentare
Les Beckham
Les Beckham am 21 Nov. 2022
FYI: you shouldn't use patch as a variable name since it is a Matlab function.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Voss
Voss am 20 Nov. 2022
Bearbeitet: Voss am 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 Kommentare
Alexandre Bernèche
Alexandre Bernèche am 21 Nov. 2022
Thank you for the fast response!
It is now working correctly with the sin change!
Have a great day :)
Voss
Voss am 21 Nov. 2022
You're welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by