A Matlab Function: in Matlab Function Block Vs. in Matlab Editor

2 次查看(过去 30 天)
Hi, I'm using a matlab function (waypoints.m) to generate an array of waypoints. The input arguments are the starting and ending points as two [1x3] arrays. The code works fine when I run it in the editor. But when I create a Simulink Matlab function block, I call the function (waypoints.m) in it, and I input the starting and ending points as two [1x3] arrays in constant blocks, I always get many errors repeated in some parts of the code, errors include:
- Index expression out of bounds,
- Function call failed, Undefined function or variable 'xxxx'. The first assignment to a local variable determines its class,
- Simulink cannot determine sizes and/or types of the outputs for block 'MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs....
Why does it work perfect in editor and not in a function block? Any help ?

回答(1 个)

Walter Roberson
Walter Roberson 2018-1-20
"The MATLAB Function block generates efficient embeddable code based on an analysis that determines the size, class, and complexity of each variable. This analysis imposes the following restrictions:
  • The first assignment to a variable defines its, size, class, and complexity.
  • See Best Practices for Defining Variables for C/C++ Code Generation.
  • You cannot reassign variable properties after the initial assignment except when using variable-size data or reusing variables in the code for different purposes.
  • See Reassignment of Variable Properties."

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by