필터 지우기
필터 지우기

vectorization of nested loop

조회 수: 1 (최근 30일)
Fabricio
Fabricio 2013년 3월 19일
Hello,
I was wondering whether it is possible to make this following nested loop into a vectorization process to make things faster and more efficient.
Y= time series with one column with 10000 observations
[M N]=size(Y);
for INCREMENT=1:100
for WINDOW=1000:INCREMENT:M
for W=WINDOW:INCREMENT:M
BB{INCREMENT,WINDOW-999}(:,W-999)=Y(W-WINDOW+1:W);
end
end
end
Thank you for your time
  댓글 수: 1
Daniel Shub
Daniel Shub 2013년 3월 19일
While you might be able to make those loops go faster with or without vectorization (try preallocating), you might want to think about how you are using BB. and why you want to hog so much memory by storing Y is a really inaccessible manner.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2013년 3월 19일
The code is not valid:
BB{INCREMENT,WINDOW-999}(W-999) = Y(W-WINDOW+1:W)
The lefthand side is a scalar, while the right hand side is a vector when WINDOW differs from 1.
The code will suffer from the missing pre-allocation. The Cell array BB and its contents will grow in each iteration, which will slow down the programm dramatically.
So currently the answer is: No. I cannot vectorize a crashing code.
  댓글 수: 1
Fabricio
Fabricio 2013년 3월 19일
Sorry about the mistake, there's (:,W-999) rather than (W-999) Y= time series with one column with 10000 observations [M N]=size(Y); for INCREMENT=1:100 for WINDOW=1000:INCREMENT:M for W=WINDOW:INCREMENT:M BB{INCREMENT,WINDOW-999}(:,W-999)=Y(W-WINDOW+1:W); end end end
Do you think it's doable?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by