How do I add these two variables? i keep on getting an error.
1 回表示 (過去 30 日間)
古いコメントを表示
function AddButtonPushed(app, event)
x =app.Input1.Value;
y =app.Input2.Value;
app.Output.Value = addition(x, y);
end
Error Message I receive
Error using matlab.ui.control.EditField/set.Value
'Value' must be a character vector or a string scalar.
Error using EngrMaeFinal/AddButtonPushed
Undefined function 'addition' for input arguments of type 'double'.
0 件のコメント
回答 (1 件)
dpb
2023 年 9 月 9 日
編集済み: dpb
2023 年 9 月 9 日
We don't know enough to be complete, but assuming the two input values are numeric, then
function AddButtonPushed(app, event)
x =app.Input1.Value;
y =app.Input2.Value;
app.Output.Value = string(x+y);
end
However, it's quite possible (likely?) you'll need to do a str2double() on the two input values that are also going to be char data in the control.
So, guessing, the function probably ought to look more like
function AddButtonPushed(app, event)
x=str2double(app.Input1.Value);
y=str2double(app.Input2.Value);
app.Output.Value = string(x+y);
end
2 件のコメント
Walter Roberson
2023 年 9 月 10 日
addition is not a MATLAB function or a method of any Mathworks-provided class that I can find.
You will need to define your own addition function.
参考
カテゴリ
Help Center および File Exchange で Software Development Tools についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!