Subsystem output disconnected automatically before running simulation

조회 수: 5 (최근 30일)
Hello people,
I have a subsystem. In the mask I added a checkbox in order to change the output of this block.
There are two possible outputs, and depending if the checkbox is checked or not, the single output of the block will be one or the other.
The problem arises when running the model. It seems that mask code is executed, so one output port is removed and substituted by the other one.
The problem is that in the upper level, the output is disconnected automatically. I did the same in other models and it was not behaving like this. Any suggestions?
Here is the code:
out = 'built-in/Outport';
term = 'built-in/Terminator';
if strcmp(get_param(gcb,'append_element'),'on')
oldOutput = [gcb '/Signals'];
newOutput = [gcb '/Signals +1'];
posOld = get_param(oldOutput,'Position');
posNew = get_param(newOutput,'Position');
orientOld = get_param(oldOutput,'Orientation');
orientNew = get_param(newOutput,'Orientation');
delete_block(oldOutput);
delete_block(newOutput);
add_block(term,oldOutput,'Position',posOld,'Orientation',orientOld);
add_block(out,newOutput,'Position',posNew,'Orientation',orientNew);
elseif strcmp(get_param(gcb,'append_element'),'off')
oldOutput = [gcb '/Signals +1'];
newOutput = [gcb '/Signals'];
posOld = get_param(oldOutput,'Position');
posNew = get_param(newOutput,'Position');
orientOld = get_param(oldOutput,'Orientation');
orientNew = get_param(newOutput,'Orientation');
delete_block(oldOutput);
delete_block(newOutput);
add_block(term,oldOutput,'Position',posOld,'Orientation',orientOld);
add_block(out,newOutput,'Position',posNew,'Orientation',orientNew);
end
clear out term

채택된 답변

Dani Tormo
Dani Tormo 2014년 2월 21일
편집: Dani Tormo 2014년 2월 21일
Well, apparently I was wrong when saying that in another block it didn't get disconnected.
Anyway, I finally solved the problem by including another condition to get into the if :
if strcmp(get_param(gcb,'append_element'),'on') &&...
~strcmp(get_param([gcb '/Signals +1'],'BlockType'),'Outport')
[...]
elseif strcmp(get_param(gcb,'append_element'),'off') &&...
~strcmp(get_param([gcb '/Signals'],'BlockType'),'Outport')
[...]
end
Basically it is checking if it has to execute a change in the outputs. If not, the code is not getting into the if.
Cheers!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subsystems에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by