I have banded matrices with lower band kl and upper band ku. I want to put them in lower triangular form and to do so, I am employing QR Householder. So, I modified the QR Householder algorithm for the lower band but can't get to a modification of the algorithm for the upper band to work. Here below, for the lower band I take the x array to only where it's non-zero. Then, when updating A, it updates a rectangular array which takes zeros from the upper band (which I would like to ignore). I've tried to vectorize that part (ignoring the zeros of the upper band) but can't get it to work.
function [U, R] = HouseH_QR(A, lowband) % so would like to add the upperband argument
[m, n] = size(A);
% algo from Trefethen with my mod for kl
% this works but not taking advantage of upperband
for k = 1:n,
kl = min(k+lowband, m); % the lower band
x = A(k:kl,k);
e = zeros(length(x),1); e(1) = 1;
u = sign(x(1))*norm(x)*e + x;
u = u./norm(u);
A(k:kl, k:n) = A(k:kl, k:n) - 2*u*u'*A(k:kl, k:n); % lower triang
U(k:m,k) = u;
end