How can I select a system/model without opening it?

6 ビュー (過去 30 日間)
Johannes
Johannes 2012 年 10 月 11 日
回答済み: Matthew Manthey 2016 年 10 月 14 日
Is there a way to select a model so that bdroot points to it without opening it?
load_system('model1');
disp(bdroot); % bdroot is now 'model1')
load_system('model2');
disp(bdroot); % bdroot is now 'model2')
% ****** 1. Code that require bdroot to be 'model2'
% ****** and 'model1' to be loaded.
% ****** 2. code that require bdroot to be 'model1'.
How can number 2 be achieved without opening model1? Another load_system('model1') doesn't do the trick. I'm looking for a select_system() I guess.
[EDIT: A better example. Please paste into an m-file called solveme.m and call from MATLAB.]
function solveme()
% bdclose all % Uncomment if you have no unsaved work
load_system('vdp');
load_system('simulink');
% Insert solution here!
% -- open_system or other commands that makes the model visible are not
% permitted
% Extra credits if close_system and bdclose are not used
disp(fcnt)
function ret = fcnt()
if strcmp(bdroot, 'vdp')
ret = 'Sucess!';
else
ret = 'Failure!';
end

回答 (4 件)

Andreas
Andreas 2016 年 9 月 28 日
This topic is very old, but I'm really interestedin this feature. Is there any new functionality within simulink api?
  1 件のコメント
Matthew Manthey
Matthew Manthey 2016 年 10 月 14 日
Me as well. Is there a select_system(), or something like it?

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


Sachin Ganjare
Sachin Ganjare 2012 年 10 月 11 日
You can use:
set_param([bdroot,'model1']) %Do check the syntax please
Hope it helps!!!
  3 件のコメント
Sachin Ganjare
Sachin Ganjare 2012 年 10 月 11 日
編集済み: Sachin Ganjare 2012 年 10 月 11 日
My bad, I did not understand the question correctly.
Before doing load_system for model1 you should close the open system i.e model2, otherwise bdroot will not point to recently loaded model.
load_system('model1');
disp(bdroot); % bdroot is now 'model1')
load_system('model2');
close_system('model1');
disp(bdroot); % bdroot is now 'model2')
Johannes
Johannes 2012 年 10 月 11 日
Thanks, that would work.

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


Kaustubha Govind
Kaustubha Govind 2012 年 10 月 11 日
I can't think of a way to switch bdroot to another model, other than Sachin's idea of closing the current bdroot model(model2 in your example). Can your code be re-written to accept the model name as an argument instead of using bdroot? In general, MATLAB functions that use bdroot, gcs and gcb tend to be too presumptive.
  2 件のコメント
Johannes
Johannes 2012 年 10 月 11 日
編集済み: Johannes 2012 年 10 月 11 日
Thanks. A select_system() would be nice, don't you agree? Especially as load_system() and open_system() apparantly has differences other than the obvious visibilty thing.
I agree on that passing the model's name as an argument is the best solution. But the function is used widely (called from other scripts) so I'm reluctant to change its interface. But I will probably go ahead and do that anyway, with an option to pass the argument or not.
Kaustubha Govind
Kaustubha Govind 2012 年 10 月 11 日
Johannes: I agree that something like select_system would be nice - could you please submit an enhancement request via MathWorks Tech Support to consider adding such an option for a future release?

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


Matthew Manthey
Matthew Manthey 2016 年 10 月 14 日
This is somewhat slow in my opinion, but I believe it serves the purpose
function select_system( obj )
% Ignore the return value
RTW.getBuildDir(obj);
end

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by