App Designer: How to pass script using object/class -methods, working in main Workspace, to function?

1 回表示 (過去 30 日間)
I am using App Designer to make a simplified GUI for a Simulink application/software Sim with complicated GUI.
Running the application Sim generates a class (in the main Workspace) called sim.
This sim is a top level class (handle) and have several methods like
'loadModel', 'runAnalysis', 'saveresult', etc
Programmatically it works to run the application and use the methods in a script like
The complicated GUI appears, gets filled with data and is run correctly. It works well!
Now I want to run this script from within a function in my simplified GUI/App Designer. Pushing a buttom is supposed to run the script.
As you can see I am following Create Multiwindow Apps in App Designer - MATLAB & Simulink - MathWorks Nordic when it comes to using several windows.
Hitting the push buttom makes the complicated GUI appear, then Matlab stops with message: ’Unable to resolve the name sim.loadModel’.
I somehow need to pass the object definition (or the methods) into the function. This object 'sim' seems to be ‘public’ and can be seen in the main workspace as soon as the application ‘Sim’ is run.
Can this be done in the function startupFcn(app)?
Am I using the wrong arguments in the function call?

回答 (1 件)

Gert Persson
Gert Persson 2021 年 6 月 17 日
No, i have not been able to sort this out. Workaround (from within the function) by using 'assignin' for creating and setting parameters in base workspace, using 'evalin' for running the commands in base workspace and then 'evalin' with 'clear' for removing traces of my not so nice fix.

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by