0

I'm trying to simulate a very simple model using an embedded matlab function that takes the input and add's 10 to the value using a constant block that inputs into the matlab function, which then outputs to a display block.

As soon as I press simulate I get an abundance of errors. First I get a huge paragraph in orange text stating a warning out the solver 'variableStepDiscrete' instead of solver 'ode45'

Here is the remaining lines that are echo'd from the command prompt:

Code Directory :
 "/Users/dazgti/Documents/MATLAB/slprj/_sfprj/embeddedFunction/_self/sfun/src"

Machine (#32): "embeddedFunction"  Target : "sfun"


Chart "MATLAB Function" (#49):

.
     "c2_embeddedFunction.h"
 "c2_embeddedFunction.c"

 "embeddedFunction_sfun.h"

 "embeddedFunction_sfun.c"

 "embeddedFunction_sfun_debug_macros.h"


Interface and Support files:

 "embeddedFunction_sfun_registry.c"

Code generation failed Attempt to execute SCRIPT union as a function:
/Users/dazgti/Documents/MATLAB/union.m

I have a script file within my matlab directory called union.m, but I have no idea why its mentioning it.

sim

function y  = fcn(u)
%#codegen

x = u + 10;

y = x;
Ryan Livingston
  • 1,898
  • 12
  • 18
user1574598
  • 3,771
  • 7
  • 44
  • 67

1 Answers1

1

MATLAB Function block works by generating "C" code for the MATLAB code you entered in the block. In the process of generating code there could have been a call to union function in MATLAB from MATLAB Function block infrastructure. Since you have overridden the union function instead of the built-in function MATLAB might have attempted to call your script which caused the error. It is better to avoid naming your functions same as MATLAB built-in functions.

Navan
  • 4,407
  • 1
  • 24
  • 26
  • Thanks. I've changed the function name to `hello(u)` and still the problem persists. I have not used my `union.m` script for a long time so I have no idea why its trying to find it. This is the first time I've tried to embed a function within simulink. – user1574598 Nov 20 '13 at 20:46
  • The only solution is to take out the `union.m` from the MatLab path which seems absurd to me. I also had another problem when initially removing the `union.m` file regarding MatLab not finding the C compiler that ships with XCode. This is now resolved except the initial problem with the `union.m` file. – user1574598 Nov 20 '13 at 21:05
  • MATLAB functions in current directory and then the ones in the path you added take precedence over the built-in ones. In MATLAB can you do "which -all union" and see what it returns? It should contain only built-in or under your MATLAB installation. – Navan Nov 20 '13 at 21:16
  • Thanks, I've typed in the command `which all union` and its returned this: `built-in (/Applications/MATLAB_R2012a_Student.app/toolbox/matlab/ops/@char/all) % char method` Do you mean that I have possibly named my own custom custom M file `union.m` the same as a built in function? – user1574598 Nov 21 '13 at 08:40
  • Rename your `union.m` to something like `my_union.m`. Close and restart MATLAB. The warnings about the solver you can ignore, it's telling you it changed the solver from `ode45` (the default) to `VariableStepDiscrete` because you don't have any continuous states in your model. – am304 Nov 21 '13 at 09:14
  • Thanks guys, yes I've renamed it to union4.m and everything is working fine now. I fully understand the original answer now, as in renaming the `union.m` file. I thought `Naven` meant rename the embedded function. The irony is that the `union.m` eminated from an official MatLab tutorial! – user1574598 Nov 21 '13 at 10:59