Subsystem output disconnected automatically before running simulation

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Dani Tormo
Dani Tormo el 21 de Feb. de 2014
Editada: Dani Tormo el 21 de Feb. de 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!

Más respuestas (0)

Categorías

Más información sobre Subsystems en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by