In the PARAFAC algorithm the fit is automatically given as an extra output. Instead of using the I/O

> Factors = parafac(X,DimX,3);

use

> [Factors,it,err] = parafac(X,DimX,3);

The additional outputs are it which is the number of iterations used and err which is the fit-value. The fit-value is in fact the objective function of PARAFAC; hence the algorithm seeks the model that produces the best least-squares approximation of the data.