Clone/ Copy a subsystem reference with new set of indexed parameters
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a large simulink model with multiple instances of a subsytem referenced blocks. Each subsytem referenec has four parameters which are indexed as shown in pictures.
For exampe for block name "E7kW_Long Range27" the parmeters are Chrg_Start_E7L(27), Batt_cap_E7L(27) etc. ie the last two digits of the block name (27) is the index of array defined in worksapce.
Is there any way that I can create a copy/ clone this block with the parameter index automatically updated. ie the copy is created as "E7kW_Long Range28" and parameters as Chrg_Start_E7L(28), Batt_cap_E7L(28) etc. with index updated to 28.
Thanks
0 个评论
采纳的回答
Ayush
2024-1-2
I understand that you want to automatically clones a subsystem and updates the parameters based on the block name in Simulink. You can create a MATLAB script to automate this process. The script would copy the subsystem, rename it, and update the parameter settings accordingly. Here is the conceptual code for that:
% Define the base block name and the current index
baseBlockName = 'E7kW_Long Range';
currentIndex = 27;
newIndex = currentIndex + 1;
% Define the subsystem's parent path
parentSystem = 'your_model_name/SubsystemParentPath';
% Define the original and new block paths
originalBlockPath = [parentSystem '/' baseBlockName num2str(currentIndex)];
newBlockPath = [parentSystem '/' baseBlockName num2str(newIndex)];
% Copy the subsystem block to the new location with the new name
add_block(originalBlockPath, newBlockPath);
% Define the parameter names
paramNames = {'Chrg_Start_', 'Batt_cap_', 'ThirdParam_', 'FourthParam_'};
% Update the parameters in the new subsystem
for i = 1:length(paramNames)
% Construct the original and new parameter names
originalParamName = [paramNames{i} 'E7L(' num2str(currentIndex) ')'];
newParamName = [paramNames{i} 'E7L(' num2str(newIndex) ')'];
% Get the original parameter value using get_param
originalValue = get_param(originalBlockPath, 'MaskValues');
% Replace the original parameter name with the new one
newValue = strrep(originalValue, originalParamName, newParamName);
% Set the new parameter value using set_param
set_param(newBlockPath, 'MaskValues', newValue);
end
% Now the new subsystem block has been created and the parameters updated
You may have to update few values in order to suit your requirement.
Thanks,
Ayush
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Schedule Model Components 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!