"Timothy Liang" <firstname.lastname@example.org> wrote in message <email@example.com>... > Hi, > > I am trying to integrate bsxfun into a loop... but it turned out to be unsuccessful... > > i=1:10000 > x=i/10000 > for q=0:20 > X=bsxfun(@power,x',q); > [Q,R]=qr(X) > ... > end > > What I want was that as q increase, the matrix would be > for q=0 > X=x1^0 > x2^0 > x3^0 > ... > > then for q=1 > X=x1^0 x1^1 > x2^0 x2^1 > x3^0 x3^1 > > for q=2 > X=x1^0 x1^1 x1^2 > x2^0 x2^1 x2^2 > x3^0 x3^1 x3^2 > and so on... > > However, the result of my codes was Xs are always 10000by1 column matrices, where the first matrix is x^0, second one x^1... > How do I fix this? Thanks in advance!!!!
You are overwriting X each time thru your for loop. You need to modify the above code to something like:
i=1:10000 x=i/10000 maxq = 21 X = zeros(maxq,length(x)) % preallocatefor efficiency for q=1:maxq X(q,:)=bsxfun(@power,x',(q-1)); [Q,R]=qr(X) ... end