MATLAB: Is there a way to get all the blocks with specific datatype (eg. boolean / ufix1) in Simulink model after compiling

data typesMATLABsignalsimulink

Is there a way to get all the blocks with specific datatype (eg. boolean / ufix1) in Simulink model after compiling

Best Answer

You can't exactly do this for blocks, because some blocks use different data types for different calculations inside of them. What you can do is get the compiled data types of ports, though.
The following code will show you how to do it for all the output ports in the "vdp" shipping example. It should all return double, but try it on one of your models and see what you get!
% Compile the vdp model
vdp([],[],[],'compile');
% Find all blocks in model
allBlocks = find_system('vdp','Type','Block');
% Loop through all blocks
for i = 1:numel(allBlocks)
lh = get_param(allBlocks{i},'PortHandles');
outports = lh.Outport;
% Loop through all output ports
for j = 1:numel(outports)
dataType = get(outports(j),'CompiledPortDataType');
% Display the data type
disp([allBlocks{i} ' output port ' num2str(j) ': ' dataType]);
end
end
% Terminate
vdp([],[],[],'term')
Right... so to get all the blocks with a specific data type, you can use logic like
if strcmp(dataType,'single')
% do something
end
- Sebastian