将 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. 大白话系列之C#委托与事件讲解(一)
  2. 动态规划-时间规整算法
  3. 删除word中所有的表格_如何在Word中删除表格
  4. 索尼首次展示其Airpeak电影摄制无人机
  5. 微信小程序支付返回信息为空
  6. 中国数码摄像机市场趋势报告、技术动态创新及市场预测
  7. JFinal 源码导读第四天(3) initRender
  8. Spring的核心思想,这篇文章短小精悍的总结透了
  9. JAVA代码 httpclient 模拟NTLM域登录 GET、POST两种连接方式
  10. 深入理解JVM虚拟机读书笔记——垃圾回收器
  11. java销毁servlet_「销毁session」Servlet销毁session - seo实验室
  12. 《IIS6下运行PHP的方法》
  13. bcd 初始化库系统卷失败_应用程序正常初始化失败怎么办
  14. 体系结构学习11-VLIW处理器
  15. 88E1111与千兆网口连接
  16. css聊天气派,css如何实现小尖角聊天对话框带尖角的说话泡泡效果
  17. js前端计算两个日期的间隔时间(时间差)
  18. Java11 主要新特性
  19. 点击遮罩层的背景关闭遮罩层(HTML)
  20. Java基础题(三)

热门文章

  1. 左旋右旋问题一次搞定!!!
  2. 这5个奇妙的Python库,你必须要试试,学python咱就是玩,欸~
  3. html向下的三角符号怎么打,哪些字符可用于上/下三角形(无茎的箭头)以HTML显示?...
  4. 分布式锁的简介与作用
  5. 免费IDM注册机下载
  6. Terragen 4生成环境贴图教程
  7. 计算机组成原理——输入/输出系统の选择题整理
  8. BootStrap-CSS样式_排版_图片
  9. 中国证券市场之[主板、中小板、创业板、科创板、新三板]
  10. 苹果和华为鸿蒙,苹果的homeOSx和华为鸿蒙,两豪杰狭路相逢