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!