Error with calling a method from one app into another
이전 댓글 표시
Hello, I am trying to call methods/functions from another app and have read you do it like this, but its not working.
1: Create the app and define the methods in the public area,
methods (Access = public)
function myTestMessage(app,msg)
disp(msg)
end
end
This is then saved as myFits.mlapp
Then in another app, I attempt to call this external method by a pushbutton call:
% Button pushed function: TestingButton
function TestingButtonPushed(app, event)
%Call external App methods form myFits app.
myTestMessage(myFits,'Test message passed to external app')
end
But I get the error:
Unrecognized function or variable 'myFits'.
댓글 수: 8
Mohammad Sami
2020년 1월 28일
편집: Mohammad Sami
2020년 1월 28일
Before you can access the method of the first app, you need to create an instance of the first app.
You can store the handle of the app as a property of your second app.
app2.myFits = myFits();
app2.myFits.myTestMessage('Test message passed to external app');
Then you can access its public method.
Jason
2020년 1월 28일
Jason
2020년 1월 28일
Mohammad Sami
2020년 1월 28일
I am assuming that your first app is called myFits() and is saved in the same folder as your second app.
The file would be called myFits.mlapp . If its called something else, you should change the code appropriately.
Jason
2020년 1월 28일
Jason
2020년 1월 28일
You have to have an actual object of the class you are trying to call the function on (since it is not a static method), and this object must be available in the scope you call it.
Where the mlapp is located in your file structure is irrelevant so long as it is on your path.
If you can create an object of myFits then it is fine wherever it is. You then have to give this object to your other app, in some way or other so that in the TestingButtonPushed function you have access to this object. Then you can call its public methods or access its public variables.
In terms of the last error, you have to define myFits in a properties block of your class if you are going to use
app.myFits = ...
Jason
2020년 1월 28일
답변 (0개)
카테고리
도움말 센터 및 File 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!