Fix stacking MATLAB code