关于Matlab/Simulink中多端选择开关功能的实现
在Simulink中有multiport switch可以实现开关选择的功能,但是在使用过程中发现multiport switch并不能将矩阵整体形式作为输入。因此,这给在Simulink中实现矩阵运算带来了一些不方便。由于multiport switch基本实现的是switch-case控制结构,因此,可以通过Simulink中的Matlab Function通过编程的方式实现选择开关的功能。但是在Matlab Function使用过程中出现了程序语句解析错误的问题(Output argument 'y' is not assigned on some execution paths;Errors occurred during parsing of MATLAB function等),下面以一个具体的实例来说明该问题的解决方法。
Matlab Function中的程序代码如下:
——————————————————————————————————————
出错的代码:
function DP=fcn(Type,Type1,Type2,Type3)
%#codegen
switch Type
在Simulink中有multiport switch可以实现开关选择的功能,但是在使用过程中发现multiport switch并不能将矩阵整体形式作为输入。因此,这给在Simulink中实现矩阵运算带来了一些不方便。由于multiport switch基本实现的是switch-case控制结构,因此,可以通过Simulink中的Matlab Function通过编程的方式实现选择开关的功能。但是在Matlab Function使用过程中出现了程序语句解析错误的问题(Output argument 'y' is not assigned on some execution paths;Errors occurred during parsing of MATLAB function等),下面以一个具体的实例来说明该问题的解决方法。
Matlab Function中的程序代码如下:
——————————————————————————————————————
出错的代码:
function DP=fcn(Type,Type1,Type2,Type3)
%#codegen
switch Type
