Opening a simulink model through same instance : App designer

I am working in MATLAB app designer. I have one instance of MATLAB GUI already open.. I have used a pushButton in app designer, which opens a simulink model when pushed. But the model is opened in a different GUI Window of MATLAB. I want the simulink model to open through same instance, which is already open.
What changes should I make in the "sim" command ?

 Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 28 Jan 2021
When you open a Simulink model, the model is always opened in the built-in, Mathworks' Simulink GUI. I don't think you can open the Simulink model in a GUI that is contained in your own APP.

13 commentaires

I am automating the process of opening a simulink model, loading the supporting *.m files, taking few inputs from user, and running the model using MATLAB App designer.
I am working on Co-Simulation between AMESim and MATLAB_simulink. I am opening the first instance of MATLAB GUI from AMESim software, so that all evvironment variables, all supporting variables, path lists are taken care. It is important for me to load MATLAB from AMESim.
Now when I run *.m files through app designer, all the variables are listed in the same GUI of MATLAB which was opened from AMESim.
As all the above things are getting done in the same GUI, I want to load the Simulink model (*.slx) in the same GUI and Run it.
* For me it is very much essential to open everything in same GUI. *
Do you mean that you have one MATLAB instance opened already by AMESim, and you want Simulink be opened in that same MATLAB instance, but now Simulink is opened in another new MATLAB instance?
Yes. Thats right. I have one MATLAB instance already open through AMESim and I want the App designer Push button to open the simulink model in the same instance..
  1. Launch your APP from AMESim to make sure your APP runs in the same MATLAB instance
  2. Lauch your APP from the MATLAB instance that has been started by AMESim
  3. See if this help https://www.mathworks.com/matlabcentral/answers/93468-why-is-a-new-instance-of-matlab-opened-when-i-double-click-on-a-matlab-file-in-windows-explorer-even?s_tid=ta_ans_results
  1. App cannot be launched through AMESim. I can open MATLAB Instance through AMESim, App will be opened from the same MATLAB Instance.
  2. I am already opening APP from th MATLAB instance which is already opened from AMESim
But when I try to open a simulink model through the APP, it opens in another MATLAB instance, not from the one already open..
What is the command/code that you use in the APP to open a Simulink model?
I have used winopen ('Filename.slx')
use open_system('FileName') instead. Or follow the link in Item 3 above, the issue should be resolved.
Thanks @Fangjun Jiang. The option worked very well as expected. But unfortunately, the requirement was bit modified and now I would like the push button to open a Browse Window which will allow me to select any file I want and open it.
I have used following code -
[file,path,indx] = uigetfile( ...
{'*.m;*.mlx;*.fig;*.mat;*.slx;*.mdl',...
'MATLAB Files (*.m,*.mlx,*.fig,*.mat,*.slx,*.mdl)';
'*.m;*.mlx','Code files (*.m,*.mlx)'; ...
'*.fig','Figures (*.fig)'; ...
'*.mat','MAT-files (*.mat)'; ...
'*.mdl;*.slx','Models (*.slx, *.mdl)'; ...
'*.*', 'All Files (*.*)'}, ...
'Select a File');
But this code opens the model in another MATLAB GUI instance.
What modification should I do to the code in order to open the simulink file from the same instance ?
Your help will be really appreciated. Thanks.
I don't understand. uigetfile() just allows the user to pick a file. It should not impact open_system('FileName') because it does not matter where the variable 'FileName' comes from?
Are you saying it is the uigetfile() dialog that brings up a new MATLAB instance?
While I use the above code, I am not using open_system('Filename') code anymore..
I was expecting that the uigetfile code opens the simulink file for me. It is opening the simulink file but from another instance of MATLAB.
Should I include open_system('filename') code along with my code ? How ?
uigetfile() is for selecting a file. It will not open the file.
FileName=uigetfile();
open_system(FileName);
Thanks @Fangjun Jiang This resolves my question. Thank you for all you help..

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Using MATLAB Projects in Simulink dans Centre d'aide et File Exchange

Produits

Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by