How do I add these two variables? i keep on getting an error.

1 回表示 (過去 30 日間)
Abraham
Abraham 2023 年 9 月 9 日
コメント済み: Walter Roberson 2023 年 9 月 10 日
function AddButtonPushed(app, event)
x =app.Input1.Value;
y =app.Input2.Value;
app.Output.Value = addition(x, y);
end
Error Message I receive
'Value' must be a character vector or a string scalar.
Undefined function 'addition' for input arguments of type 'double'.

回答 (1 件)

dpb
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 件のコメント
Abraham
Abraham 2023 年 9 月 9 日
編集済み: Abraham 2023 年 9 月 9 日
+++ I tried implenting your code and it doesnt work out either.
My two inputs are numeric. I am trying to add input1 to input2 and have it appear in the Output box. I am having trouble with my third line of where i cannot add my input1 and input2 because i get an error. Ive tried using the sum operator but i get an error message as well. I dont know the proper operator to add my two inputs.
*** I also get value must be a double scalar error
% Button pushed function: AddButton
function AddButtonPushed(app, event)
x=app.Input1.Value;
y=app.Input2.Value;
app.Output= addition(x,y);
end
Error message
Unrecognized function or variable 'addition'.
Error in EngrMaeFinal/AddButtonPushed (line 26)
app.OutputEditField.Value = addition(x,y);
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ...
Error while evaluating Button PrivateButtonPushedFcn.
Walter Roberson
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 ExchangeSoftware Development Tools についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by