将 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            =-I\Omega*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 模块使用问题求教相关推荐

  1. 在MATLAB中使用数学符号,在matlab中怎么输入特殊符号 function在MATLAB中怎么用

    导航:网站首页 > 在matlab中怎么输入特殊符号 function在MATLAB中怎么用 在matlab中怎么输入特殊符号 function在MATLAB中怎么用 相关问题: 匿名网友: 一 ...

  2. matlab中dist的命令,matlab dist函数

    dist--欧式距离加权函数(Euclidean distance weight function) 语法: Z = dist(W,P) df = dist('deriv') D = dist(pos ...

  3. matlab中错误使用fmincon,MATLAB中fmincon 函数问题

    MATLAB中fmincon 函数问题 Matlab的fmincon优化问题 请问: 各位高手帮忙看看我的程序又什么问题?显示错误 Error in ==> Fun at 33 [w,fval] ...

  4. matlab中signal在哪里,matlab中Signal Builder模块的用法总结

    在网上搜了好久,关于matlab中Signal Builder模块的使用方法很少,由于做仿真时需要用到这个模块,无奈自己摸索过后在此总结下使用方法: 双击Signal Builder模块弹出如下对话框 ...

  5. matlab中rastrigin图形绘制,matlab函数function

    x?6 x?6 (1) 利用MATLAB语言编写S函数.程序如下: function [sys,x0,str,ts]=sfunction(t,x,u,flag) switch flag, case 0 ...

  6. matlab中clock是什么,matlab中的clock

    其值为真 Why 简明的答案 Version MATLAB 版本号 时间和日期 Clock 挂钟 Date 日历 Etime 计时函数 Tic 秒表开始计时 Toc 计时函数 Cputime CPU ...

  7. matlab中集合的表示,Matlab常用命令集合

    1.常用命令-->管理命令和函数 addpath添加目录到MATLAB搜索路径doc在Web浏览器上现实HTML文档help显示Matlab命令和M文件的在线帮助helpwin helpdesk ...

  8. matlab中scope是什么,matlab中的scope

    如何编辑 simulink 仿真结果 scope 中的图形 matlab 中输入... matlab_simulink_示波器_scope图片属性设置_计算机软件及应用_IT/计算机_专业资料.毕业季 ...

  9. matlab中scope是什么,matlab中scope

    MATLAB_simulink中的示波器scope设置_数学_自然科学_专业资料... 精品文档 Matlab Figure 图形保存以及 Simulink 中 Scope 窗口坐标标注(label) ...

最新文章

  1. esl8266开发之旅_从ESL老师到越南软件开发人员的旅程
  2. [ASP.NET MVC] 利用自定义的AuthenticationFilter实现Basic认证
  3. 谱聚类算法(Spectral Clustering)优化与扩展
  4. 网络分流器-网络分流器-网络安全评估探讨
  5. 当Java 8 Streams API不够用时
  6. C++ 常用集合算法
  7. 前端学习(781):格式化日期年月日星期
  8. 神经网络快速搭建之一站式访问
  9. 作业8 单元测试练习
  10. Windows域控 批量设置用户下次登录 修改密码【全域策略生效】
  11. 计算机基础知识真题模拟7,计算机一级考试计算机基础及Photoshop应用模拟试题(7)...
  12. C++ 后台开发面试时一般考察什么?
  13. MC9S12G128模块化分层化软件架构之八_QAC静态代码分析
  14. 掌门教育三大举措落实个性化教学 让“因材施教”落到实处
  15. html css javascript七夕情人节表白网页【樱花雨3D相册】超好看
  16. HDU 4417 Super Mario(划分树问题求不大于k的数有多少)
  17. 【C语言基础】练习题
  18. 李炎恢-在线商城第三季总结
  19. 大彩科技新品首发--新1代HMI人机界面!
  20. 【iOS-iap防护】验证用户付费收据!拒绝iap Cracker!拒绝iap Free!让iphone越狱用户无从下手!【2012年5月2日更新防护iap Free的方法】

热门文章

  1. 【爬虫】简单爬取和处理数据
  2. Python2写csv文件中文乱码问题及解决方法详解
  3. c++ 多线程 “锁”
  4. IDM下载器最新稳定版本6.33.2
  5. JRebel and XRebel idea热部署插件的使用
  6. 四缸汽油机曲轴及凸轮轴信号生成(基于STM32)
  7. 系统校验矩阵怎么求_软考高级架构师:计算机系统基础知识
  8. 什么叫数据与程序的物理独立性?什…
  9. SIP开源项目opensip,Freeswitch
  10. pandas数据处理-----(一)