Q:

Vectorizing slow code in matlab

I have been trying to vectorize this code for a while, but have been unable to. Can someone help please.
    %X -[153600x400]
    %W -[153600x500]
    %beta=error=scalar
    %errvals=[40x1]
    %n=400
    iter = 1;
    for ii = 1:n 
        disp(ii);
        x = X(:,ii);
        y = W'*x;        
        W = beta*x*y' + W - beta*W*tril(y*y');       
        beta = options.rate*options.annealfunc(iter);       
        err = err + sum((x - W*(W'*x)).^2);
        errvals(iter) = err/iter;       
        if (any(~isfinite(W)))
            warning(sprintf('Lost convergence at iterator %i; lower learning rate?', niter));
            success = 11;
            break;
        end;       
        if (options.printerr == 1)
            fprintf('Error = %d; Iteration = %i\n', err/iter, iter);
        end;        
        iter = iter+1;
    end;

A:

Vectorization is no "magic" suddenly improving the performance, it basically cuts away the overhead for function calls and iteration. In your case, a loop with 400 iterations and only some function calls, the overhead is minimal. 
Without actually running your code because I don't have all inputs (at least options.annealfunc is missing) I would guess that most of the time is spend performing the matrix multiplications. The right way to improve the performance of matrix multiplications is running them on a GPU. Assuming you have a compatible graphic card and a license for the distributed computing toolbox, you have to convert your arrays to gpuArrays

