필터 지우기
필터 지우기

calling a function inside an app?

조회 수: 29 (최근 30일)
Abdelrahman Taha
Abdelrahman Taha 2020년 1월 8일
댓글: Abdelrahman Taha 2020년 1월 8일
Hi,
I am trying to understand how to call a function inside an app. So, I've created a simple app to get the sum of two numbers (a,b), and c is their sum. There's a pushbutton in the app whose function is to run this created functon outside the app and assign the outcome to the variable "c". However when I run the app, I get this error:
Unable to resolve the name app.a.
Error in su (line 2)
c = app.a + app.b;
This is the app code
properties (Access = public)
a % Description
b % Description
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function: aEditField
function aEditFieldValueChanged(app, event)
app.a = app.aEditField.Value;
end
% Value changed function: bEditField
function bEditFieldValueChanged(app, event)
app.b = app.bEditField.Value;
end
% Button pushed function: Button
function ButtonPushed(app, event)
su;
app.cEditField.Value = c;
And this is the "su" function
function su
c = app.a + app.b;
end
Any help on why I get this error would be really appreciated.
Thanks

채택된 답변

J. Alex Lee
J. Alex Lee 2020년 1월 8일
Functions need inputs and outputs, so you will need to define the function su as
function out = su(app)
out = app.a+app.b
end
and inside your app
function ButtonPushed(app, event)
c = su(app);
app.cEditField.Value = c;
end
Now, as to whether this structure for the app and function is a good structure, that's a separate question.
  댓글 수: 1
Abdelrahman Taha
Abdelrahman Taha 2020년 1월 8일
Thanks for your help, it's working.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop 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