Is it possible to make a while error or while no error Matlab
조회 수: 7 (최근 30일)
이전 댓글 표시
Hello !
In my matlab script i'm parsing a text file with a specific tag structure and creating Simulink Block for each occurence of a special Tag i found. A simple example i have this :
[Link]
Link_Name : On/Off
Link_ID : _sZfSkku9Eemg_bhrv2HEbw
[Link]
Link_Name : On/Off
Link_ID : _qsYbsVeeEemna8dVWPKMTw
You can see that this is not the same Object but they have the same name and so when in matlab i create a simulink block for each Link i found i have an error
"can't create a new On/Off Block"
something like that.
So i put the ID in the description of the Block and if it's the same i just update the name in case of if the user changed the name in the text file :
set_param(gcb,'Name', link_NameValue);
If it's different i create a new Block :
add_block('simulink/Ports & Subsystems/In1',[component_NameValue '/' link_NameValue], 'MakeNameUnique', 'on');
The problem is with " 'MakeNameUnique', 'on' " it will create an infinity of Block if i run my script many times
and with set_param i have an error
The name 'On_Off' already exists
So i would like to make a while loop like this :
while error "can't create a new block"
add a "x" at the end of the name of the new block
end
or
while error "The name 'On_Off' already exists"
add a "x" at the end of the name of the existing block
end
So even if i have 4 [Link] with the name On/Off it will create On/Off, On/Offx, On/Offxx, On/Offxxx or with number at the end if it's possible.
Thanks for helping ! I tried to explain as short as i could.
댓글 수: 0
답변 (1개)
Ben Cunningham
2019년 4월 16일
I don't quite follow the use of 'while' here but if I understand correctly then hopefully the following will be useful.
So something like :
try
% <your parse / create block code>
catch ME
switch ME.message
case "can't create a new block"
% add a "x" at the end of the name of the new block
case "The name 'On_Off' already exists"
% add a "x" at the end of the name of the existing block
otherwise
rethrow(ME)
end
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!