How to display a graph after getting user to input in the pop up?

2 次查看(过去 30 天)
Question:
A window should pop up that asks the user to input a single variable equation (a.k.a. function) for which the user wishes to find the root.
ii) A graph of this equation should get displayed
My code:
prompt = {'Single variable equation: \color{white} .'};
dlg_title = 'Input';
num_lines = 1;
defaultans = {'x'};
options.Interpreter='tex';
answer = inputdlg(prompt,dlg_title,num_lines,defaultans,options);
func = string(answer{1});
What to do next? New to MATLAB, please help.

采纳的回答

Walter Roberson
Walter Roberson 2017-9-9
  6 个评论
Walter Roberson
Walter Roberson 2017-9-12
How do I know that you are not going to just delete your question after I answer it? When you delete your question after I have answered, you treat me as if I am a free private consultant. If you want a private consultation then you can hire a private consultant; if you want free advice then the price we charge is that your question and the responses must remain public for everyone to learn from.
Walter Roberson
Walter Roberson 2017-9-12
The meaning of
@(x) func
is the same as
@(x) func()
which means that a local variable named "x" is to be accepted on input, and then func() is to be called with no parameters.
The syntax
@(x) func(x)
would mean that a local variable named "x" is to be accepted on input, and then func() is to be called passing that variable as a parameter. @(x) func(x) means almost exactly the same thing as @func alone without the (x) part, except that using @(x) func(x) will only work if exactly one input is provided, whereas @func would work if multiple inputs are provided if func accepts multiple inputs.
In
f = str2func((['@(',char(symvar(func)),')', func]));
then notice the symvar(func) and at that point func is a character vector. symvar(func) looks through the string to figure out which variable the user used -- so for example if the user had entered 'sin(t).^2' then symvar would return the 't' . When symvar is used properly, the user is not restricted to using a particular variable name.
The above code constructs @(VARIABLENAME) CODE . In the 'sin(t).^2' example, @(t) sin(t).^2 would be constructed; if the user had coded 'besselj(1/2, x)' then @(x) besselj(1/2,x) would be constructed.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by