how to insert an equation in a edit fill

5 Ansichten (letzte 30 Tage)
jose ramire
jose ramire am 8 Mär. 2019
Beantwortet: Walter Roberson am 9 Mär. 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);

Antworten (2)

Cris LaPierre
Cris LaPierre am 9 Mär. 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 am 9 Mär. 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.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by