Clear Filters
Clear Filters

Vectorizing nested for loops

3 views (last 30 days)
William
William on 30 Jun 2011
Hello, I'm relatively new to Matlab and am having some difficulties vectorizing my code. Although I'm sure that the answer to my question exists somewhere, I confess that I haven't yet found it. Anyway, I'm trying to vectorize the following nested for loops: for i=2:rho {for|j=1:zDim {phi(i,j) = phi(1,j)/(1+i)}}
It's certainly just a rookie question, but I appreciate any advice.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 30 Jun 2011
bsxfun(@rdivide,phi,(1+(2:rho))')
here phi vector row
or use first row of 'phi' matrix
bsxfun(@rdivide,phi(1,:),(1+(2:rho))')

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!