The situation:
I'm coding a heavy simulation model, that runs on a Matrix which could be quite big (say 1025*1025 cells). In every swipe (numel(myMatrix)
iterations) of the model the matrix is passed between functions, and most of the time it is changed (so MATLAB does not pass it by reference). Because there is a huge number (several millions) of iterations I use Mex code for the core of the model, and only pass the simulation parameters to it.
My question: In order to save some time I used global variable for the main matrix, but I read all over the web that this is a big 'NO! NO!'. So I tried to use nested functions instead, but then I found that "Nested functions are currently unsupported for code generation". So, what should I do? Is there a smart way to avoid globals (which I tend to dislike in my code) and some how implement the idea of nested function in a MEX file?
Any help will be appreciated!