how to insert an equation in a edit fill

5 ビュー (過去 30 日間)
jose ramire
jose ramire 2019 年 3 月 8 日
回答済み: Walter Roberson 2019 年 3 月 9 日
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 Center および File ExchangeDevelop 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