MATLAB Answers

How can I output the Simulink Model Version in model_initialize c function?

8 ビュー (過去 30 日間)
Michael Frena
Michael Frena 2020 年 10 月 16 日
コメント済み: Michael Frena 2020 年 11 月 3 日
I am trying to ouput the model version information in the generated c code. Preferable would be to have it generated in the model_initialze function.
But curretly I am facing the problem that both commands to retrieve the model version information are not usable with the ert code generator:
1) info = Simulink.MDLInfo('mymodel') % works only in releases after R2009b
2) modelVer = get_param(modelname, 'versionLoaded')
Whats the best way to get the version info into the code?


Chidvi Modala
Chidvi Modala 2020 年 10 月 29 日
You may follow these steps to include MATLAB version, Subversion revision number, and code generation settings in auto-generated code from Simulink models.
  • In that custom section, add a comment block with the information which you want to include in the auto-generated code.
  • For MATLAB version you can use the following code.
%openfile tmpBuf
MATLAB Version : %<FEVAL("version", "-release")>
%closefile tmpBuf
Which resulted in this:
MATLAB Version : 2015a
  • The SVN revision is a little trickier. There is no direct way to access the revision from the command line, so the SVN command line needs to be used instead.
>> !svn info -r HEAD [[filename]]
Path: [[filename]]
Name: [[filename]]
Repository Root:
Repository UUID:
Revision: 1059 <----Revision number!
Node Kind: file
Last Changed Author:
Last Changed Rev:
Last Changed Date:
  • Note the presence of the revision number. You can use the FEVAL command in TLC to execute an m-function to call the SVN command and parse out the revision number.
  • Alternatively, you can also use the following command to return the data in an XML format which will be easier to parse through.
>> !svn info -r HEAD [[Filename]] --xml
  • To include code generation settings, you can use FEVEL command in TLC to execute an m-function which will have many "get_param" calls to obtain all the code generation parameters of your interest. To know the parameter name, simply right-click and click "What's this?" on the parameters in the "Code Generation" pane of "Model Configuration Parameters". A window will appear with all details of that parameter.
  2 件のコメント
Michael Frena
Michael Frena 2020 年 11 月 3 日
In fact to output the model version I added the following function call to the tlc file:
%openfile tmpBuf
modelVersion = 0b%<FEVAL("getVersionInfo")>;
%closefile tmpBuf
I defined the getVersionInfo m-function like this:
function verOut = getVersionInfo()
verIn = get_param(gcs, 'ModelVersion');
VersionInfo = strsplit(verIn, '.');
major = bitshift(str2num(VersionInfo{1}),12,'uint16');
minor = uint16(str2num(VersionInfo{2}));
verOut = dec2bin(major + minor);


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by