MATLAB: How to connect to IF and IFACTION blocks programmatically

simulink script add_line if

Hi, we are generating simulink via m script and using add_line but this doesn't seem to work for adding a line to or between if condition and action blocks as they don't have port numbers. Is there another command to do this? Thanks Colin

Best Answer

% Get If block port handles
If_ph = get_param('If block path','porthandles');
% Get If action block port handles
Action_ph = get_param('If action block path','porthandles');
% Connect
add_line('Your model',If_ph.Outport(1),Action_ph.Ifaction);
% Note
% If_ph.Outport(1) for "If" port
% If_ph.Outport(2) for "Else" port