MATLAB: Make Error in Simulink – Division by Zero

division by zeromake errorMATLABsimulink

I looked up Make Errors here, and most of the issues were solved by calling 'mex -setup'. I gave that a shot, and everything looked fine. I'm using MATLAB R2011a Student Version along with its built-in lcc C Compiler.
My Simulink model consists of two MATLAB functions, some constants and 'From Workspace' sources. One of the MATLAB functions is 154 lines long and includes four extrinsic functions, all of which are declared as such at the beginning of the function. The other is basically a placeholder and passes the outputs as the same as inputs.
Here are the errors, buried in a long error report:
Error c2_cogen2_simulink.c: 5380 Division by zero
Error c2_cogen2_simulink.c: 5383 Division by zero
Error c2_cogen2_simulink.c: 5411 Division by zero
Here's the full error report, in case it sheds more light on the issue:
Making simulation target "cogen2_simulink_sfun", ...
C:\Users\Zack\Documents\Italy Research\cogen1\slprj\_sfprj\cogen2_simulink\_self\sfun\src>"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\bin\lccmake" -f cogen2_simulink_sfun.lmk
Warning c1_cogen2_simulink.c: 482 static `void function(pointer to void,pointer to const incomplete struct mxArray_tag defined at C:\Program Files (x86)\MATLAB\R2011a Student\extern\include\matrix.h 298,pointer to const char,pointer to void) c1_c_sf_marshallIn' is not referenced
Warning c1_cogen2_simulink.c: 455 static `pointer to const incomplete struct mxArray_tag defined at C:\Program Files (x86)\MATLAB\R2011a Student\extern\include\matrix.h 298 function(pointer to void,pointer to void) c1_c_sf_marshallOut' is not referenced
0 errors, 2 warnings
Error c2_cogen2_simulink.c: 5380 Division by zero
Error c2_cogen2_simulink.c: 5383 Division by zero
Error c2_cogen2_simulink.c: 5411 Division by zero
Warning c2_cogen2_simulink.c: 6780 static `void function(pointer to void,pointer to const incomplete struct mxArray_tag defined at C:\Program Files (x86)\MATLAB\R2011a Student\extern\include\matrix.h 298,pointer to const char,pointer to void) c2_u_sf_marshallIn' is not referenced
Warning c2_cogen2_simulink.c: 6753 static `pointer to const incomplete struct mxArray_tag defined at C:\Program Files (x86)\MATLAB\R2011a Student\extern\include\matrix.h 298 function(pointer to void,pointer to void) c2_u_sf_marshallOut' is not referenced
Warning c2_cogen2_simulink.c: 6671 static `double function(pointer to SFc2_cogen2_simulinkInstanceStruct,double) c2_sign' is not referenced
Warning c2_cogen2_simulink.c: 6570 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,int,double,int,int,pointer to double,int,int,pointer to double,pointer to int,int,int,pointer to double,pointer to int) c2_ceval_xger' is not referenced
Warning c2_cogen2_simulink.c: 6524 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,int,double,pointer to double,pointer to int,int,int,pointer to double,pointer to int,int,int,double,pointer to double,int,int,pointer to double) c2_ceval_xgemv' is not referenced
Warning c2_cogen2_simulink.c: 6480 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,int,pointer to double,pointer to int,int,int,pointer to double,pointer to int,int,pointer to double,pointer to double) c2_eml_blas_xgemv' is not referenced
Warning c2_cogen2_simulink.c: 6452 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,int,int,double,pointer to double,pointer to int,int,int,pointer to double,pointer to double,pointer to int,pointer to double) c2_eml_matlab_zlarf' is not referenced
Warning c2_cogen2_simulink.c: 6443 static `double function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,double,double,int,int) c2_b_ceval_xscal' is not referenced
Warning c2_cogen2_simulink.c: 6434 static `double function(pointer to SFc2_cogen2_simulinkInstanceStruct,double,double) c2_b_eml_xscal' is not referenced
Warning c2_cogen2_simulink.c: 6425 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,double,double,pointer to double,pointer to double,pointer to double) c2_b_eml_matlab_zlarfg' is not referenced
Warning c2_cogen2_simulink.c: 6403 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,double,pointer to double,pointer to int,int,int,pointer to double,pointer to int) c2_ceval_xscal' is not referenced
Warning c2_cogen2_simulink.c: 6383 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,double,pointer to double,pointer to int,int,pointer to double,pointer to int) c2_eml_xscal' is not referenced
Warning c2_cogen2_simulink.c: 6331 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,double,pointer to double,pointer to int,int,pointer to double,pointer to double,pointer to int,pointer to double) c2_eml_matlab_zlarfg' is not referenced
Warning c2_cogen2_simulink.c: 6309 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,pointer to double,pointer to int,int,int,int,int,pointer to double,pointer to int) c2_ceval_xswap' is not referenced
Warning c2_cogen2_simulink.c: 6287 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,pointer to double,pointer to int,int,int,int,int,pointer to double,pointer to int) c2_eml_refblas_xswap' is not referenced
Warning c2_cogen2_simulink.c: 6265 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,pointer to double,pointer to int,int,int,int,int,pointer to double,pointer to int) c2_eml_blas_xswap' is not referenced
Warning c2_cogen2_simulink.c: 6245 static `void function(pointer to SFc2_cogen2_simulinkInstanceStruct,int,pointer to double,pointer to int,int,int,pointer to double,pointer to int) c2_eml_xswap' is not referenced
3 errors, 17 warnings
"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\bin\lcc.exe" -c -Zp8 -DMATLAB_MEX_FILE -noregistrylookup -I"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\extern\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\simulink\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\mex\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\debugger\include" "cogen2_simulink_sfun.c"
"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\bin\lcc.exe" -c -Zp8 -DMATLAB_MEX_FILE -noregistrylookup -I"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\extern\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\simulink\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\mex\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\debugger\include" "cogen2_simulink_sfun_registry.c"
"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\bin\lcc.exe" -c -Zp8 -DMATLAB_MEX_FILE -noregistrylookup -I"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\extern\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\simulink\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\mex\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\debugger\include" "c1_cogen2_simulink.c"
"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\bin\lcc.exe" -c -Zp8 -DMATLAB_MEX_FILE -noregistrylookup -I"C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\extern\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\simulink\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\mex\include" -I"C:\Program Files (x86)\MATLAB\R2011a Student\stateflow\c\debugger\include" "c2_cogen2_simulink.c"
C:\Program Files (x86)\MATLAB\R2011a Student\sys\lcc\bin\lccmake: Error code 1
Thanks for any help you can give.
Zack

Best Answer

Turns out, trying to use 'load' and 'save' as extrinsic functions in a MATLAB Function Block in Simulink doesn't work.
That situation has been replaced by global variables, Data Store Memory Blocks, and an If Action Subsystem. The If Action Subsystem has variables being loaded from the workspace through Constant Blocks and loaded into Data Store Write Blocks.
Everything works fine, now.
Thanks anyway,
Zack
Related Question