Optimization! Divide a vector by each element of another vector!

조회 수: 2 (최근 30일)
M G
M G 2013년 11월 28일
댓글: M G 2013년 12월 1일
Dear all,
I would like to optimize my code which looks like this:
for n = 1:N
prt1(n,:) = exp(exp1/n^2);
end
exp1 is a vector of (1,2e4) and N = 2e4.
As you see the loop above works fine but the problem is heavy computation which takes extremely long time. Is there any way that I can vectorize n? By that I need to divide each element of exp1 by the 1st element of n and then 2nd, 3rd, ... nth element of n.
Any hint is appreciated :)
All the best
PS: Any good source in general for the MATLAB optimization??

채택된 답변

Walter Roberson
Walter Roberson 2013년 11월 29일
prt1 = bsxfun(@rdivide, exp1, (1:N).');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by