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

2 visualizzazioni (ultimi 30 giorni)
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 ?

Risposte (1)

Walter Roberson
Walter Roberson il 20 Gen 2018
"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."

Categorie

Scopri di più su Simulink Functions in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by