概述
将 M 文件中的代码拷贝到Matlab Function模块中直接使用会出现错误
代码如下:
function out =abscontroller(in)
alpha =in(1);
beta =in(2);
sigma =in(3);
theta =[alpha;beta;sigma];
p =in(4);
q =in(5);
r =in(6);
w =[p;q;r];
alpha_ref =in(7);
beta_ref =in(8);
sigma_ref =in(9);
theta_ref =[alpha_ref;beta_ref;sigma_ref];
dalpha_ref =in(10);
dbeta_ref =in(11);
dsigma_ref =in(12);
dtheta_ref =[dalpha_ref;dbeta_ref;dsigma_ref];
% ddalpha_ref =in(13);
% ddbeta_ref =in(14);
% ddsigma_ref =in(15);
% ddtheta_ref =[ddalpha_ref;ddbeta_ref;ddsigma_ref];
% vs =in(13:15);
delta_1g =in(13);
delta_2g =in(14);
zI =in(15:17);
%%
% I =[1997922 0 0;0 276629966.8 0;0 0 28383800.1];
I =[434270 0 -17880;0 961200 0;-17880 0 1131541];
% Ixx=434270*(1+0); Iyy=961200*(1+0); Izz=1131541*(1+0);
% Ixz=17880*(1+0);
R =[0 1 0;sin(alpha) 0 -cos(alpha);-cos(alpha) 0 -sin(alpha)];
Omega =[0 -r q;r 0 -p;-q p 0];
%%
k1 = 25*diag([1 1 1]);
k2 = 25*diag([3 3 3]);
kI = 0;
c1 = 2;
a1 = 0.01;
eta1 = 0.0001;
a2 = 0.01;
c2 = 2;
eta2 = 0.0001;
%%
z =theta-theta_ref;
ztheta =z+kI*zI;
% dztheta =R*w-dtheta_ref;
zf =norm(ztheta);
delta1 =c1*a1*delta_1g*ztheta/(zf+eta1);
wd =R(-k1*ztheta+dtheta_ref-delta1-kI*z);
% % %%
if zf>=eta1/(c1-1);
ddelta_1g =c1*a2*zf^2/(zf+eta1);
else
ddelta_1g =0;
end
%%
z1 =w-wd;
zf2 =norm(z1);
fw =-IOmega*I*w;
% dvs =epslion*[sign(z1(1));sign(z1(2));sign(z1(3))];
delta2 =c2*a2*delta_2g*z1/(zf2+eta2);
if zf2>=eta2/(c2-1);
ddelta_2g =c2*a2*zf2^2/(zf2+eta2);
else
ddelta_2g =0;
end
%%
M =I*(-k2*z1-fw-delta2);
out =[M;ddelta_1g;ddelta_2g;zI];
错误提示如下:
Index expression out of bounds. Attempted to access element 2. The valid range is 1-1.
More information
Function 'MATLAB Function' (#35.94.95), line 5, column 18:
"2"
Launch diagnostic report.
Component: MATLAB Function | Category: Coder error
Index expression out of bounds. Attempted to access element 3. The valid range is 1-1.
More information
Function 'MATLAB Function' (#35.115.116), line 6, column 18:
"3"
Launch diagnostic report.
Component: MATLAB Function | Category: Coder error
……
Simulink does not have enough information to determine output sizes for
this block. If you think the errors below are inaccurate, try specifying
types for the block inputs and/or sizes for the block outputs.
Component: MATLAB Function | Category: Coder error
Undefined function or variable 'theta'. The first assignment to a local variable determines its class.
Function 'MATLAB Function' (#35.1245.1250), line 52, column 15:
"theta"
Launch diagnostic report.
Component: MATLAB Function | Category: Coder error
经实验,将该M文件放在Interpreted Matlab Function中可以正常使用。
推测是Matlab Function相比于Interpreted Matlab Function 在变量输入或赋值上有特殊的限制。
论坛视频区都看过了,没有发现关于Matlab Function 的相关教程,故求老司机解疑答惑并最好能推荐一些关于Matlab Function模块的教程~
最后
以上就是专一发箍为你收集整理的MATLAB中assignment模块,Simulink Matlab Function 模块使用问题求教的全部内容,希望文章能够帮你解决MATLAB中assignment模块,Simulink Matlab Function 模块使用问题求教所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复