フィルターのクリア

Avoid loops with mapping toolbox "setltln"

2 ビュー (過去 30 日間)
Robert Jenkins
Robert Jenkins 2015 年 8 月 4 日
回答済み: Sean de Wolski 2015 年 8 月 4 日
Hi all, I'm looking for a clever way to optimize the following chunk of code. The function is to get a grid of lat, lon coordinates using the reference matrix R, and the indices of Z.
However, with such huge dimensions, this nested for loop is painfully slow! How can I avoid for loops in this case?
[Z, R] = arcgridread('biloxi_ms.asc');
tempLAT=zeros(9721,10801);
tempLON=zeros(9721,10801);
for i =1:9721
for j = 1:10801
[tempLAT(i,j), tempLON(i,j)] = setltln(Z, R, i, j);
end
end
Best, Rob

採用された回答

Sean de Wolski
Sean de Wolski 2015 年 8 月 4 日
You could build a grid and call setltln on all of it. This will consume a bit more memory since you'll need to store ii, jj. A hybrid approach might be to run a loop over smaller meshgrids.
[ii, jj] = meshgrid(1:9271,1:10801)
[tempLAT, tempLON]= setltln(Z, R, ii, ij);
Also, parallel computing could help here if you have the parallel computing toolbox. Simply, turn the outer loop into a parfor.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeExecution Speed についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by