Calculate or check how many memory you need from workspace window.
You need a “continuous” block of memory for a matrix.
1. make the biggest matrix smaller
2. assign memory for the biggest matrix at beginning of running
Please refer Memory Management Guide http://www.mathworks.com/support/tech-notes/1100/1106.html