Error with calling a method from one app into another

6 views (last 30 days)
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 Comments
Adam
Adam on 28 Jan 2020
Edited: Adam on 28 Jan 2020
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 = ...

Sign in to comment.

Answers (0)

Categories

Find more on Sample Class Implementations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!