MATLAB: Moving large matrix from function workspace to base workspace

basemat2strMATLABmatrixworkspace

I am debugging a program and want to get some matrix data out of the program and into the base workspace, so I can probe it and try a fews things on it. How can I do this? I having been uising the following command, but the mat2str function takes a while (and also adds on extra precision for some reason):
evalin('base', ['datamat = ' mat2str(data) ';'])

Best Answer

The correct function to use is assignin, not evalin:
assignin('base','data',data)
Probably even better would be to just use the debugging tools: use a breakpoint to stop the code on a suitable line, and then look at whatever variables you want. This means you do not need to add code or change the function, and gives you access to all variables in that workspace: