how to insert an equation in a edit fill

5 views (last 30 days)
jose ramire
jose ramire on 8 Mar 2019
Answered: Walter Roberson on 9 Mar 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);

Answers (2)

Cris LaPierre
Cris LaPierre on 9 Mar 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 on 9 Mar 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.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!