Calculate clusters and store for use in Matlab