MATLAB has a built-in profiler that is very useful to profile your code and find out what script or function is taking the most time.
To run a script in the profiler, open the script file and click Run and Time in the top menu. After running the script, the profiler gives a hyperlinked colorful graph of functions and the times they took.
From Command Window
The equivalent of the above operation in commands is:
profile on; run_my_script; profile off; profile viewer
Tried with: MATLAB R2014a and Ubuntu 14.04