How to display a graph after getting user to input in the pop up?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
oshawcole
el 9 de Sept. de 2017
Comentada: Rena Berman
el 14 de Sept. de 2017
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.
1 comentario
Respuesta aceptada
Walter Roberson
el 9 de Sept. de 2017
6 comentarios
Walter Roberson
el 12 de Sept. de 2017
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
el 12 de Sept. de 2017
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!