How do you plot a circle with a str2func()?

I was wanting to plot a circle using the str2func(). I'm able to plot the x section but the y section will not work. Thanks!
edit: I"m asking this for a friend, I'm trying to help him with a script that he's trying to write, but I"m not sure how to implement the str2func() to pick up the y values as well as the x values if a user inputs the x and y values.

답변 (1개)

Matt J
Matt J 2021년 11월 1일
No idea why you think str2func should be part of the task. Why not simply,
fimplicit(@(x,y) x.^2+y.^2-100,11*[-1,+1,-1,+1]); axis equal

댓글 수: 4

Perhaps you were aiming for something like this?
fun=str2func( '@(x,y) x.^2+y.^2-100' );
fimplicit(fun,11*[-1,+1,-1,+1]); axis equal
KG
KG 2021년 11월 1일
I'm asking for a friend and he's trying to have someone input an equation into the command section using a function and then do a vertical line test to determine if the inputted equation is a function. He's wanting the user to input a string and then plot that string (by converting it using the str2func())and have his script determine if it passes the vertical line test. I think this may be what he is aiming for.
KG
KG 2021년 11월 1일
I know it's confusing.
S = input('Enter a function in x and y: ', 's');
fun = str2func( "@(x,y) " + S);

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

KG
2021년 11월 1일

댓글:

2021년 11월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by