fetch masked subsystem LSB value using Matlab script
显示 更早的评论
am unable to fetch the LSB value in my model but am getting for all other block exept for masked subsystem using script
回答(1 个)
Soumya
2025-8-5
I understand that you are trying to fetch the ‘LSB’ value from a block inside a masked subsystem in Simulink using MATLAB scripts, and while it works for normal blocks, it fails for masked subsystems because the parameters are hidden behind the mask. To access parameters inside a masked subsystem, you need to use the ‘LookUnderMasks’ option in ‘find_system’. This option tells MATLAB to look inside masked blocks and return the internal blocks that would otherwise remain hidden, which is necessary to locate the block holding the ‘LSB’ value.
To resolve this issue, you can follow the given steps:
- Use ‘find_system’ with the 'LookUnderMasks' as 'all' to confirm that internal block path exists:
allBlocks = find_system(gcs, 'FollowLinks', 'on', 'LookUnderMasks', 'all', 'BlockType', 'Outport');
- If you have defined it as a parameter, fetch the ‘LSB’ directly as a defined parameter from the path of the internal block obtained, for example:
lsbVal= get_param(allBlocks{1},'LSB');
disp(lsbVal)
- If not, loop through blocks and check for fixed-point data type, and find ‘LSB’:
for i = 1:length(allBlocks)
dataTypeStr = get_param(allBlocks{i}, 'OutDataTypeStr');
if contains(dataTypeStr, 'fixdt')
dt = Simulink.NumericType(dataTypeStr);
lsbValue = 2^(-dt.FractionLength);
fprintf('Block: %s -> Computed LSB: %g\n', allBlocks{i}, lsbValue);
else
fprintf('Block: %s -> Not fixed-point\n', allBlocks{i});
end
This method ensures MATLAB recognizes the proper hierarchy for masked subsystems and allows you to reliably retrieve or compute ‘LSB’ values without running into indexing or object name errors.
Please refer to the following documentations to get more information on the related functions:
- ‘Simulink.NumericType’:https://www.mathworks.com/help/simulink/slref/simulink.numerictype.html
- ‘find_system’:https://www.mathworks.com/help/simulink/slref/find_system.html
- ‘get_param’:https://www.mathworks.com/help/simulink/slref/get_param.html
I hope this helps!
类别
在 帮助中心 和 File Exchange 中查找有关 Subsystems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!