efficient use of find and ismember
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuesta aceptada
dpb
el 25 de Abr. de 2014
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!