nested loops/vectorization/array indexing
古いコメントを表示
Hello,
I am currently working with a series of nested loops where an array is modified upon each loop and each loop iteration depends on the index of different variables. Here is an example:
for jj = 1:J %Loop over Y variables
for ii = 1:I %Loop over X variables
for l = 1:Nm %Loop for each value of l
m = mod(l-1,M+1);
n = floor((l-1)/(M+1));
S(l,ii,jj) = cos(m*pi*X(ii)/Lx)*cos(n*pi*Y(jj)/Ly);
end
end
end
The problem I am having is how to vectorize this computation to improve speed. Note that X and Y are coordinates in 2-d. Is it possible to improve this so that it can be performed more quickly?
Thanks
1 件のコメント
Oleg Komarov
2012 年 2 月 12 日
supply example inputs.
採用された回答
その他の回答 (1 件)
Cameron
2012 年 2 月 12 日
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!