How do I draw circles in App Designer with user inputting the x, y and radii values?

7 次查看(过去 30 天)
Hi,
So i am creating a project where I need to be able to draw multiple circles with different x, y and radii values. I was able to make one circle but it had a fixed radius and I would like it to be such that the user can input the different values and that is then used to plot the circle. This is what I have written down so far. I would appreciate any help I can get!
clear;
r = 4;
caca = 2*pi;
ang = linspace(0,caca);
xp = r*cos(ang);
yp = r*sin(ang);
circ = [xp;yp];
figure(1)
plot(xp,yp)
I tried writing:
r = inputdlg;
but it just wouldn't work. I mean it would allow the user to input the value but wouldn't plot a circle.
Any ideas on how I can get the user to enter the x, y and radii values and have it plot perfectly on a graph. I also want it to plot multiple circles.
Thank you!

回答(1 个)

VBBV
VBBV 2022-12-17
In the app designer, you can invoke the follwing code,
% in the app designer
prompt = {'Enter radius of circle:', 'Enter centre:'}
T_L = 'Circle'
dims = [1 40]
out = inputdlg(prompt,T_L,dims)
caca = 2*pi;
ang = linspace(0,caca);
r = str2num(out{1});
C = str2num(out{2});
xp = C(1)*cos(ang);
yp = C(2)*sin(ang);
plot(xp,yp,'r-')
  11 个评论
Dev Chhatbar
Dev Chhatbar 2022-12-17
编辑:Dev Chhatbar 2022-12-17
@Image Analyst- Yes! That's a good point. I wonder why I didn't change that. You're right. Those are three things my user would need to enter. And based off of that, I'm meant to apply those inputs and plot the circles and then find the intersection point and draw tangential lines!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by