Meaning code setDatType RefMdl

8 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2023-1-3
It is rude to delete all of your comments in a thread; doing that removes all of the context for what the volunteers contributed.

请先登录,再进行评论。

采纳的回答

Kiran Kintali
Kiran Kintali 2022-12-25
This code is looking for specific block name patterns and based on block name assigning output types for the blocks.
  3 个评论
Walter Roberson
Walter Roberson 2022-12-26
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
Walter Roberson 2022-12-28
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'));

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by