SubSystem block does not have a parameter named 'MATLABFunction'
7 次查看(过去 30 天)
显示 更早的评论
% Create a new Simulink model
modelName = 'mySimulinkModel';
new_system(modelName);
open_system(modelName);
% Add a MATLAB Function block to the model
blockPath = [modelName, '/MyMATLABFunction'];
add_block('simulink/User-Defined Functions/MATLAB Function', blockPath);
% Set the function code in the MATLAB Function block
functionCode = sprintf('function y = fcn(u)\n y = u^2;\nend');
set_param(blockPath, 'MATLABFunction', functionCode);
% Optionally, set block position
set_param(blockPath, 'Position', [100, 100, 200, 150]);
% Save and close the model
save_system(modelName);
close_system(modelName);
0 个评论
回答(1 个)
Paul
2025-7-22
The function code in the Matlab Function block can be modified programatically using MATLABFunctionConfiguration
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!