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

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

Accepted Answer

Sebastian Castro
Sebastian Castro on 19 Jun 2015
Edited: Sebastian Castro on 19 Jun 2015
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

More Answers (0)

Categories

Find more on Event Functions in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!