How can I change the size of a circle patch?
3 views (last 30 days)
Alexandre Bernèche on 20 Nov 2022
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)
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');
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
Voss on 20 Nov 2022
Edited: Voss on 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.