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 ?

 採用された回答

Fangjun Jiang
Fangjun Jiang 2021 年 1 月 28 日

0 投票

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 件のコメント

Amit Patankar
Amit Patankar 2021 年 1 月 29 日
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. *
Fangjun Jiang
Fangjun Jiang 2021 年 2 月 1 日
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?
Amit Patankar
Amit Patankar 2021 年 2 月 1 日
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..
Fangjun Jiang
Fangjun Jiang 2021 年 2 月 1 日
  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
Amit Patankar
Amit Patankar 2021 年 2 月 2 日
  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..
Fangjun Jiang
Fangjun Jiang 2021 年 2 月 2 日
What is the command/code that you use in the APP to open a Simulink model?
Amit Patankar
Amit Patankar 2021 年 2 月 3 日
I have used winopen ('Filename.slx')
Fangjun Jiang
Fangjun Jiang 2021 年 2 月 3 日
use open_system('FileName') instead. Or follow the link in Item 3 above, the issue should be resolved.
Amit Patankar
Amit Patankar 2021 年 2 月 3 日
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.
Fangjun Jiang
Fangjun Jiang 2021 年 2 月 3 日
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?
Amit Patankar
Amit Patankar 2021 年 2 月 3 日
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 ?
Fangjun Jiang
Fangjun Jiang 2021 年 2 月 3 日
uigetfile() is for selecting a file. It will not open the file.
FileName=uigetfile();
open_system(FileName);
Amit Patankar
Amit Patankar 2021 年 2 月 3 日
Thanks @Fangjun Jiang This resolves my question. Thank you for all you help..

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeUsing MATLAB Projects in Simulink についてさらに検索

製品

リリース

R2017a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by