フィルターのクリア

efficient use of find and ismember

2 ビュー (過去 30 日間)
Dan
Dan 2014 年 4 月 24 日
回答済み: dpb 2014 年 4 月 25 日
Hello,
I have 2-D array (~250000 x 2) that has repeated rows. I need to find the indices of the repeated rows and take a mean over those rows with another variable. The code I have below works fine, but it is VERY slow. In this example the variable 'latlon' is the 2-D array (1st column is latitude and 2nd column is longitude).
uniq = unique([latlon],'rows');
for i = 1:length(uniq)
pairs = find(ismember(latlon,uniq(i,:),'rows'));
%use pairs indices to grab data from another 1-D variable
newdata(i) = mean(SLP(pairs))
end
This currently takes ~4hrs to run for the 250,000 row array. Can anyone help me improve the efficiency here?
Thanks,
Dan

採用された回答

dpb
dpb 2014 年 4 月 25 日
The "deadahead" solution (w/o accumarray, I'm to brain-tired this evening to write that off the cuff... :) )
[~,ia,ic]=unique(latlon,'rows','stable');
new=zeros(size(ia));
for i=1:length(ia)
new(i) = mean(SLP(ia(i)==ic));
end
I think I got that right...

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by