Error with calling a method from one app into another

5 visualizaciones (últimos 30 días)
Jason
Jason el 28 de En. de 2020
Comentada: Jason el 28 de En. de 2020
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 comentarios
Adam
Adam el 28 de En. de 2020
Editada: Adam el 28 de En. de 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 = ...
Jason
Jason el 28 de En. de 2020
Perfect, thankyou

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Sample Class Implementations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by