1, NK);
options = {<span class="string">'maxIter'</span>, 10, <span class="string">'verbose'</span>, true};
model = cell(1, NK);
<span class="keyword">for</span> i=1:NK
    K = Kvalues(i);
    fprintf(<span class="string">'Fitting K = %d \n'</span>, K)
    model{i}  = mixDiscreteFit(Xtrain, K, options{:});
    logp(i)   = sum(mixDiscreteLogprob(model{i}, Xtest));
    nParams   = K*d + K-1;
    bicVal(i) = -2*logp(i) + nParams*log(n);
<span class="keyword">end</span>
</pre><pre class="codeoutput">Fitting K =