Adding Polynomials Using App Designer

10 ビュー (過去 30 日間)
jinji gneiss
jinji gneiss 2022 年 7 月 18 日
コメント済み: jinji gneiss 2022 年 7 月 23 日
I am new to matlab and I am trying to create a calculator that adds polynomials. I want the user to input something like 3*x+1 and 4*x+1 and have a result of 7*x+2. here is my code but when I try it, it does not display any answer:
% Button pushed function: AddButton
function AddButtonPushed(app, event)
a = str2num(app.fxEditField.Value);
b = str2num(app.gxEditField.Value);
res = a+b;
app.ResultEditField.Value = num2str(res);
end

採用された回答

Kevin Holly
Kevin Holly 2022 年 7 月 20 日
How did you want your user to input the data? As for the calculations, see below for an example.
app.fxEditField.Value = [3 1];
app.gxEditField.Value = [4 1];
AddButtonPushed(app)
a = 
b = 
res = 
app = struct with fields:
fxEditField: [1×1 struct] gxEditField: [1×1 struct] ResultEditField: [1×1 struct]
function AddButtonPushed(app, event)
a = poly2sym(app.fxEditField.Value)
b = poly2sym(app.gxEditField.Value)
res = a+b
app.ResultEditField.Value =res
end
  3 件のコメント
Kevin Holly
Kevin Holly 2022 年 7 月 23 日
Please see app attached.
app.fxEditField.Value = '3*x+1';
app.gxEditField.Value = '4*x+1';
AddButtonPushed(app);
res = 
ResultEditField_Value = '7*x + 2'
Below is the callback for the "Add" button.
function AddButtonPushed(app, event)
a = str2sym(app.fxEditField.Value);
b = str2sym(app.gxEditField.Value);
res = a+b;
app.ResultEditField.Value = char(res);
end
jinji gneiss
jinji gneiss 2022 年 7 月 23 日
This is exactly what I am looking for! Thank you very much I got it working already. My mistake was I didn't consider char(res).

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by