1

我正在尝试使用 MATLAB delete_block 函数,给定一个 simulink 块路径会删除该块。不幸的是,如果块的名称包含 a它由于转义/而无法删除该块。/例如,如果完整路径是:

system/subsystem/outputBlock[rad/s]

delete_block删除块失败(不报告任何失败)。在一条不是由 delete_block 函数生成的警告消息中,我发现该块的路径报告为:( system/subsystem/outputBlock[rad//s]最后/转义)。所以可能发生的事情是路径被转义并且找不到,因为不是搜索system/subsystem/outputBlock[rad/s],而是delete_block搜索system/subsystem/outputBlock[rad//s]。为了验证这一点,我尝试通过删除最后一个来手动更改块的名称,/并且该delete_block功能可以正常工作。如何删除路径名中名称包含的块/

4

1 回答 1

4

Hope, I can help here. The // is the escape sequence for the / character. If you want to delete blocks with the // in the name, I think it best to recurse down the tree to get the fully qualified name and escape any / at each point.

% get the name of the block you want to delete, we'll just use gcb() for now
blk = gcb;
nameList = {};
% get the name of this block
currBlk = get_param(blk,'Name')
nameList{end+1} = currBlk;
% get the name of the root block diagram
rootName = bdroot(blk)
while( ~strcmp(get_param(blk,'Parent'),rootName) )
  currBlk = get_param(blk,'Parent');
  nameList{end+1} = get_param(currBlk,'Name');
end
nameList{end+1} = rootName;
% for completeness, here's a naive attempt to reconstruct the path
str='';
for ii=length(nameList):-1:1
  str = [str strrep(nameList{ii},'/','//') '/' ];
end
str(end) = []; % get rid of the last '/'

HTH!

于 2013-02-22T16:11:29.077 回答