how to insert an equation in a edit fill

5 visualizaciones (últimos 30 días)
jose ramire
jose ramire el 8 de Mzo. de 2019
Respondida: Walter Roberson el 9 de Mzo. de 2019
i'm using app designerand i need that the user introduce a equation. with the variable 'x' like 2*x+1
i using this but doesn't take the equation
j=app.t.Value;
g=@(x) j;
app.c.Value=g(2);

Respuestas (2)

Cris LaPierre
Cris LaPierre el 9 de Mzo. de 2019
What do you mean by 'doesn't take the equation'? What is the expected behavior? How have you created this in app designer?
If I have to edit fields (numeric) in my app, if I set up the callback for edit field t this way, it works.
% Value changed function: t
function tValueChanged(app, event)
j = app.t.Value;
g=@(x) j;
app.c.Value=g(2);
end
The way you've written you anonymous function, it will always return the value of j no matter what value you use when calling g. So if j=5, app.c.Value is 5 despite assigning it g(2). If you want it to use the value you are passing in, update your anonymous function to use the variable you specified with '@'
g=@(x) x;

Walter Roberson
Walter Roberson el 9 de Mzo. de 2019
g = str2func( ['@(x)', app.t.Value]);
assuming here that app.t.Value is a character vector that is the equation in x to be evaluated.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by