fetch masked subsystem LSB value using Matlab script

3 Ansichten (letzte 30 Tage)
hruthik
hruthik am 30 Jun. 2025
Beantwortet: Soumya am 5 Aug. 2025
am unable to fetch the LSB value in my model but am getting for all other block exept for masked subsystem using script

Antworten (1)

Soumya
Soumya am 5 Aug. 2025
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:
I hope this helps!

Kategorien

Mehr zu Subsystems finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2015b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by