How do I separate the contents of my MATLAB Function blocks from my SLX file for easier version control?
조회 수: 5 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2020년 10월 22일
답변: MathWorks Support Team
2021년 9월 16일
I am using MATLAB Function blocks in my Simulink model to incorporate MATLAB Code. However, the code inside these blocks is saved with the SLX file, meaning it's very difficult for me to track changes to the MATLAB Functions via source control. How can I save the contents of my MATLAB Function block separately from my SLX?
채택된 답변
MathWorks Support Team
2020년 10월 22일
The most straightforward way to do this is via a nested function call. You can define your MATLAB Function in a separate .m file, and then call that function from the MATLAB Function Block. See the 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
Another way to achieve this workflow is to use a MATLAB Interpreted Function block, but this block does not support code generation at this time.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 User-Defined MATLAB Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!