Meaning code setDatType RefMdl
6 views (last 30 days)
Show older comments
Hello everyone, could someone explain to me what this function mean ? Thank you in advance
function setDataType(ConstantHdl)
BlockName=get_param(ConstantHdl,'Name');
is_ev=~isempty(regexp(BlockName,'^EV_\w*','once'));
if is_ev
if strcmp(get_param(ConstantHdl,'BlockType'),'Constant')
set_param(ConstantHdl,'OutDataTypeStr','Inherit: Inherit via back propagation');
else
set_param(ConstantHdl,'OutDataTypeStr','Inherit: auto');
end
else
is_prm=~isempty(regexp(BlockName,'^\w*_prm_\w*','once'));
if is_prm
prefix_regexp='^\w*_prm';
else
prefix_regexp='^\w*';
end
is_bool=~isempty(regexp(BlockName,sprintf('%s_(%s)[A-Z]\\w*',prefix_regexp,'b'),'once'));
is_int=~isempty(regexp(BlockName,sprintf('%s_(%s)[A-Z]\\w*',prefix_regexp,'ct|idx|no|st'),'once'));
is_int8=~isempty(regexp(BlockName,sprintf('%s_(%s)[A-Z]\\w*',prefix_regexp,'bf'),'once'));
if is_int
set_param(ConstantHdl,'OutDataTypeStr','int32');
elseif is_bool
set_param(ConstantHdl,'OutDataTypeStr','boolean');
elseif is_int8
set_param(ConstantHdl,'OutDataTypeStr','int8');
elseif ~isempty(regexp(BlockName,'\w*_[A-Za-z]\w*','once'))
set_param(ConstantHdl,'OutDataTypeStr','single');
else
if strcmp(get_param(ConstantHdl,'BlockType'),'Constant')
set_param(ConstantHdl,'OutDataTypeStr','Inherit: Inherit via back propagation');
else
set_param(ConstantHdl,'OutDataTypeStr','Inherit: auto');
end
end
end
set_param(ConstantHdl,'AttributesFormatString','type=%<OutDataTypeStr>');
end
1 Comment
Walter Roberson
on 3 Jan 2023
It is rude to delete all of your comments in a thread; doing that removes all of the context for what the volunteers contributed.
Accepted Answer
Kiran Kintali
on 25 Dec 2022
This code is looking for specific block name patterns and based on block name assigning output types for the blocks.
3 Comments
Walter Roberson
on 26 Dec 2022
Are you asking us to look through the list of blocks on the right hand side of that image, and figure out what the patterns are in the block names that match the datatypes given in the middle, and tell you what new regexp patterns you should use?
Walter Roberson
on 28 Dec 2022
is_int=~isempty(regexp(BlockName,sprintf('%s_(%s)[A-Z]\\w*',prefix_regexp,'ct|idx|no|st'),'once'));
Currently, the |st part says that if the block name matches _st then this block is an example of an integer block.
If you want to change that so that st blocks are single instead of integer, then remove the |st part of the expression, making it
is_int=~isempty(regexp(BlockName,sprintf('%s_(%s)[A-Z]\\w*',prefix_regexp,'ct|idx|no'),'once'));
More Answers (0)
See Also
Categories
Find more on Use COM Objects in MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!