Subsystem output disconnected automatically before running simulation

5 views (last 30 days)
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

Accepted Answer

Dani Tormo
Dani Tormo on 21 Feb 2014
Edited: Dani Tormo on 21 Feb 2014
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!

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!