speed up a for loop

4 ビュー (過去 30 日間)
Giacomo Abrardo
Giacomo Abrardo 2021 年 4 月 18 日
コメント済み: Giacomo Abrardo 2021 年 4 月 18 日
Hi i have a double foor loop like this where N3=1376 and N1=498.
I need to speed up the double loop because in one day of running i just have a 1376*68 matrix. The first solution i considered is to preallocate the matrix SM outside the double loop but i don't know if that will be enough. Do you have any suggestions? Thanks all

採用された回答

Walter Roberson
Walter Roberson 2021 年 4 月 18 日
編集済み: Walter Roberson 2021 年 4 月 18 日
Inside your inner for loop, you read three .nc files. For efficiency, you need to reduce the number of files you need. So reverse the order of your loops
for j = 1 : N3
FileNC=P{j}
ncdisp(FileNC);
latidudine = ncread(FileNC, 'lat');
longitudine = ncread(FileNC, 'lon');
umidata = ncread(FileNC, 'ssm');
do the two find and through to sm=sm*0.5
for k = 1 : N1
LAT = Latitudine_stazioni(k,1);
LONG = Lognitudine_stazioni(k,1);
[val1,idx1] = min(abs(Long-LONG));
and through to the end of your loop, to the assigment to SM(j,k)
end
end
  1 件のコメント
Giacomo Abrardo
Giacomo Abrardo 2021 年 4 月 18 日
thank you very much

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by