How do I manage the contents of MATLAB Function blocks via source control?
6 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2020 年 12 月 30 日
編集済み: MathWorks Support Team
2021 年 3 月 3 日
I have a Simulink Model with MATLAB Function blocks. I want to manage the scripts inside these blocks with version control. Since the contents of the MATLAB Function blocks are embedded in the SLX file as binaries, I cannot identify readable changes to the MATLAB scripts using git. Is there a workaround for this?
採用された回答
MathWorks Support Team
2021 年 3 月 3 日
編集済み: MathWorks Support Team
2021 年 3 月 3 日
The most straightforward way to do this is via a nested function call, such that your MATLAB Function block contains a call to another MATLAB Function on your path which resides in a standalone M file. This way, you can manage the standalone M file with your source control software of choice. See an example below:
% In the MATLAB Function Block code
function y = fcn(u)
y = foo(u);
end
% In a separate M file on the MATLAB Path:
function z = foo(x)
z = x^2;
end
This way, when the MATLAB Function Block is executed, it will call a function definition stored in a separate M file which can be managed line-by-line with source control.
As another potential workaround, the Model Comparison Tool within Simulink is able to compare, merge, and revert changes to MATLAB Function blocks within SLX files. This tool can be integrated with git so that it is automatically launched when performing diff and merge commands.
Here is a brief video which describes the Model Comparison Tool workflow and demonstrates it for a three-way merge:
For more information about using the Comparison Tool for a two-way model merge, see the link below:
For more information about configuring git to use the Model Comparison Tool, see the link below:
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!