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

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

Risposta accettata

Sebastian Castro
Sebastian Castro il 19 Giu 2015
Modificato: Sebastian Castro il 19 Giu 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

Più risposte (0)

Categorie

Scopri di più su Event Functions in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by