The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Integrating bsxfun in a for-loop
Replies: 1   Last Post: Feb 23, 2014 5:02 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 2,359
Registered: 12/6/04
Re: Integrating bsxfun in a for-loop
Posted: Feb 23, 2014 5:02 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Timothy Liang" <> wrote in message <leb9qk$qn0$>...
> 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:

maxq = 21
X = zeros(maxq,length(x)) % preallocatefor efficiency
for q=1:maxq

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.