MATLAB: How to get list of constant blocks in model and its default value in Matlab

simulink

I would like to see the names of all the constant blocks in my model along with its default values, is there any way to get it?

Best Answer

I would recommend you investigate the "find_system" function in the help files.
The first command you need is likely some variant of:
constantBlocks = find_system(bdroot,'LookUnderMasks','all','BlockType','Constant');
I'm not certain what you mean by the "default" values of the constant blocks. But the find_system command will give you a list of constant blocks, which you can cycle through access the strings in the "Value" parameter on each block, if that's what you're looking for.
numConstant = size(constantBlocks,1);
blockValues = cell(numConstant,1);
for ptr = 1:numConstant
blockValues{ptr} = get_param(constantBlocks{ptr},'Value');
end
From there, you should be able to see the value, or evaluate the parameter assigned to the value.