Need help in code optimization for distance calculation between points.
Afficher commentaires plus anciens
Hello everyone. I need to know if there is a way to optimize my code. This part (which concentrates 95% of the computing time) takes about 15 seconds on my computer, and the section that is taking the longest time is calculating the distance (line 20). This time is really large, considering that this is only one region of a larger map and in addition it only equals one iteration of 96. The total time of my program considering all iterations would be 8 hours. Any ideas?
clear;% clc;
load('vars_optimiz.mat','-mat');
time_clc=tic;
polyg='Polyg #1';
fprintf('\n%s (%i:00)',polyg,Dates.H);
n_cell_activ=0;
alfn(size(DATA_Value,1))=0.0;
gaman(size(DATA_Value,1))=0.0;
val_es(size(DATA_Value,1))=0.0;
sum_m1=0;
sum_m2=0;
for x=1:size(mapa,2)
for y=1:size(mapa)
sum2_th=0;
sum2_id=0;
if mapa(y,x) ~= 0
n_cell_activ=n_cell_activ+1;
xx=base_x+x; yy=base_y+y;
alft=0;
n_dist=(((DATA_x_s-xx) .^ 2) + ((DATA_y_s-yy) .^ 2)) .^ 0.5; %Distance Calculation
[val_min_dist,cell_min_dist]=min(n_dist);
n_dist(n_dist==0)=0.0000000000000001;
sum_m1=sum_m1+DATA_Value(cell_min_dist);
alfn=1./(n_dist.^2);
alft=sum(alfn);
gaman=alfn/alft;
val_es=gaman.*DATA_Value;
val_tot=sum(val_es);
sum_m2=sum_m2+val_tot;
end
end
end
med1=sum_m1/n_cell_activ;
med2=sum_m2/n_cell_activ;
fprintf(' "%s",%i-%i-%i %i:00 - Med1: %.8f Med2: %.8f Segs: %.4f\n',polyg,Dates.Y,Dates.M,Dates.D,Dates.H,med1,med2,toc(time_clc));
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Direct Search dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!