Thanks for your suggestion, Phil. It makes sense to me. However, when I had the chance to try it out, I found that while the syntax ?mxSetPr(array_ptr, &varMEX);? allows the code to compile, it actually causes a crash when the system runs. (If I comment out this line, the code runs with no problems.) If my code is given below, any suggestions about what else could be the issue, such that running this code results in crash behavior? Thanks.