First, find out the version of gcc you need to have installed:
That link is for R2012a, look at the "System Requirements and Supported Compilers Archive" link if you have an earlier version.
Then install the required compiler using "aptitude install gcc-4.4", or from the software installer. If Ubuntu doesn't allow that command directly, you may need to look up techniques for installing an older gcc with a new one on the same machine.