2013-02-22 76 views
1

我想使用MATLAB delete_block函數,它給出了一個simulink塊路徑刪除塊。 不幸的是,如果塊的名稱包含/,則由於/轉義而無法刪除該塊。 如果例如完整路徑是:Simulink逃生delete_block

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

希望,我可以幫到這裏。 ///字符的轉義序列。如果你想刪除名稱中的//的塊,我認爲最好在樹上進行遞歸以獲得完全限定的名稱,並在每個點處轉義任何/

% 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!