Matlab 枚举Simulink中块的输入端口和输出端口

Matlab 枚举Simulink中块的输入端口和输出端口,matlab,block,ports,simulink,Matlab,Block,Ports,Simulink,在Simulink中,如何有问题地枚举块的输入和输出句柄?到目前为止,我已尝试使用以下方法,其中“sfunc”已设置为块句柄: inports = get_param(sfunc, 'Inport') outports = get_param(sfunc, 'Outport') 它返回一个二维数组,其大小等于指定端口数。但是当我运行以下命令时(使用'inport'或'outport') 它声明数组必须是向量。我这样做对吗?如果是这样,我如何将数组转换成向量?基本上,我要做的是获取连接到块的线的

在Simulink中,如何有问题地枚举块的输入和输出句柄?到目前为止,我已尝试使用以下方法,其中“sfunc”已设置为块句柄:

inports = get_param(sfunc, 'Inport')
outports = get_param(sfunc, 'Outport')
它返回一个二维数组,其大小等于指定端口数。但是当我运行以下命令时(使用'inport'或'outport')


它声明数组必须是向量。我这样做对吗?如果是这样,我如何将数组转换成向量?基本上,我要做的是获取连接到块的线的句柄,以便在用新块替换当前块后,可以将它们连接起来。如果您对此有任何帮助,我们将不胜感激。

尝试使用参数PortHandles,这将为您提供一个包含诸如Inport、Outport、EnablePort等字段的结构。Inport和Outport字段将是一个句柄数组,即端口数的大小

>> ph = get_param(sfunc, 'PortHandles')
>> inportHandles = ph.Inport;
% Get the 2nd input port handle
>> input_2 = inportHandles(2);
>> line = get_param(input_2, 'Line');
>> ph = get_param(sfunc, 'PortHandles')
>> inportHandles = ph.Inport;
% Get the 2nd input port handle
>> input_2 = inportHandles(2);
>> line = get_param(input_2, 'Line');