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

5 次查看(过去 30 天)
Is there a way to get all the blocks with specific datatype (eg. boolean / ufix1) in Simulink model after compiling

采纳的回答

Sebastian Castro
Sebastian Castro 2015-6-19
编辑:Sebastian Castro 2015-6-19
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by