MATLAB: How to increase the stack size of the S-function or MEX file in MATLAB

MATLAB

In writing a MEX file or S-function, I have allocated a large amount of automatic memory. The memory is allocated by declaring arrays with their size specified at
the beginning of the main function. At run time, I get an "Unexpected Internal Error", but it works fine if I decreases the amount of memory being used.

Best Answer

There is no way to increase the stack size of a MEX file or S-function in MATLAB. However, you may be able to resolve this issue by moving some of your data from the stack to dynamically allocated memory. That is, use mxMalloc or mxCalloc to allocate memory in your function.
For more information about the mxMalloc and mxCalloc functions, please refer to the following documentation pages: