2013-02-22 2 views
1

MATLAB delete_block 함수를 사용하려고합니다.이 함수는 시뮬 링크 블록 경로에서 블록을 삭제합니다. 블록 이름에 /이 포함 된 경우 /이 (가) 탈출하여 블록을 삭제할 수 없습니다. 예를 들어 전체 경로 인 경우 :delete_block을 사용하여 Simulink 탈출

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!