Subsystem output disconnected automatically before running simulation

2 次查看(过去 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