Coding closed and open quantum systems in MATLAB : applications in quantum optics and condensed matter