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');
- 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);
fprintf('Block: %s -> Not fixed-point\n', allBlocks{i});
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:
I hope this helps!