Why do I get an error when in my CallBack?
52 ビュー (過去 30 日間)
古いコメントを表示
In my function my two inputs are numeric. I am trying to add input1 to input2 and have it appear in the Output box. I am able to edit my input boxes and insert values but my issue comes when i push my Add button. The third line of my code is where i get my error.
All the codes Ive tried:
% Button pushed function: AddButton
function AddButtonPushed(app, event)
x=app.Input1.Value;
y=app.Input2.Value;
app.Output.Value= 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.
% Button pushed function: AddButton
function AddButtonPushed(app, event)
x=str2double(app.Input1.Value);
y=str2double(app.Input2.Value);
app.Output.Value = string(x+y);
end
Error while evaluating Button PrivateButtonPushedFcn.
Error using EngrMaeFinal/AddButtonPushed
'Value' must be a double scalar.
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.
3 件のコメント
Walter Roberson
2023 年 9 月 10 日
app.Output is the name of the output box that you want your sum to appear in, and Value is a property of that box. I am asking what the class() of app.Output is, because the class() affects the permitted property values.
回答 (1 件)
Sachin
2023 年 9 月 13 日
Hi Abraham,
I understand that you are getting an error in the callback function. The issue could be because of an incorrect class type. For example: You are adding two double values and in the Edit field you are returning the result as a string. It will give an error if the Edit field accepts a double value. So, you must match the output with the accepted class type for that field.
For the 1st error, the issue is that there is no function named ‘addition’ in your code.
For the 2nd error, the issue could be because the field wants a double value to show but you are giving a string value.
Refer to the following steps to work with an example:
- Create a design like below by adding suitable fields.
2. Add a callback function for Button.
3. Implement the logic in the callback function.
I hope the above example helped in resolving the issue that you are encountering.
Thanks
Sachin
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!