question for using MATLAB Compiler (mc) for Undefined function

I created a .m file that is used to generate subsystem for my simulink model. I want to use it in cmd, so that i compiled it by using
mcc -m myprogram.m
it generate a myprogram.exe file I run this file but it returns error
??? Undefined function or method 'open_system' for input arguments of type 'char'.
my program.m
function convert2subsys(sys)
open_system(sys);
blocks = find_system(sys, 'SearchDepth', 1);
bh = [];
% for i = 2:length(blocks)
bh = [bh get_param(blocks{2}, 'handle')];
% end
Simulink.BlockDiagram.createSubSystem(bh);
end
Please help. I am using matlab 2010(a); btw, should i use the matlab coder rather then matlab compiler?

回答 (1 件)

Friedrich
Friedrich 2011 年 7 月 12 日

0 投票

Hi,
the Simulink Products are not made for compiling:
Maybe consider calling MATLAB with the -r option in order to run you program from the cmd

5 件のコメント

yizhan
yizhan 2011 年 7 月 12 日
my batch file
win D:\Program Files\MATLAB\R2010a\bin\matlab.exe -nosplash -nodesktop -minimize
start matlab -nosplash -nodesktop -minimize matlab -r convert2subsys('new') -logfile c:\temp\logfile
i did write a batch file, but the matlab and simulink window will open. When i try to close it in .m file use "exit", it ask me if i want to save the new model. In case, i can not really auto close the model... is there anyway to do it?
yizhan
yizhan 2011 年 7 月 12 日
Thank you ...
Friedrich
Friedrich 2011 年 7 月 12 日
Maybe do a load_system instead of open_system and then do a save_system before calling close_system
Kaustubha Govind
Kaustubha Govind 2011 年 7 月 12 日
You can use close_system with the save flag parameter:
close_system('mymodel', 0); % close without saving
(or)
close_system('mymodel', 1); % close after saving
This will prevent the save dialog from popping up.
yizhan
yizhan 2011 年 7 月 13 日
Thank you guys, it works now. The simulink process is been done invisibly.
There is only one window opening... which is the "matlab command window" is there a way to close it? I mean in batch file.
I have tried taskkill, but is will prevent the matlab file running.

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

カテゴリ

ヘルプ センター および File ExchangeCreate Large-Scale Model Components についてさらに検索

質問済み:

2011 年 7 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by