how to insert an equation in a edit fill

5 次查看(过去 30 天)
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);

回答(2 个)

Cris LaPierre
Cris LaPierre 2019-3-9
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 2019-3-9
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.

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by