How can I Improve the efficiency of the following code?

1 回表示 (過去 30 日間)
Emanuele Massaro
Emanuele Massaro 2015 年 7 月 9 日
編集済み: Emanuele Massaro 2015 年 7 月 9 日
Hello I have this loop
id = unique(DATA(:,3));
rg = zeros(length(id),4);
for i = 1 : size(id,1)
x = y(DATA(:,3)==id(i));
rg(i,1) = sum(sqrt((Y(x,4) - Xm(id(i),1)).^2 + (Y(x,3) - Xm(id(i),2)).^2 ))./size(x,1);
rg(i,2) = id(i);
rg(i,3) = Xm(id(i),1);
rg(i,4) = Xm(id(i),2);
end
It is a very slow process. Is there a way to improve it? In particular I would like to avoid the first line after the loop and do it with accumarray or similar function. Thank you.

回答 (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