How can I speed up my Code?
    3 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
Good evening,
I have a problem with the performance of my Code, as Im new to matlab.
I hope the comments help you to understand everything.
The main problem is, that most of the time I have no points at the x-coordinate. Thats why I interpolate the closest and the secound closest. But that I have to do for every AeroDataId, so every Mach/CL combination in my database. To speed it up a little bit, I only use the points in a certin mach and Cl delta.
load('new_upper_airfoil');
%% searched point
Ma=0.7;
C_l=0.65;
%% delta of cl and Mach
cl_delta=0.015;
Ma_delta=0.015;
%% delta of the points in the original pressure distribution
Delta=2/height(originalDV);
DV=zeros(height(originalDV),2);
Temp=array2table(zeros(0,4),'VariableNames',{'X_C','CP','Ma','CL_res'});
Temp_update=array2table(zeros(0,4),'VariableNames',{'X_C','CP','Ma','CL_res'});
i=1;
%% load only the points within a Mach Number and Lift coefficient delta
new_upper_airfoil=new_upper_airfoil(new_upper_airfoil.Ma < (Ma+Ma_delta) & new_upper_airfoil.Ma > (Ma-Ma_delta) & new_upper_airfoil.CL_res < (C_l+cl_delta) & new_upper_airfoil.CL_res > (C_l-cl_delta),:);
new_lower_airfoil=new_lower_airfoil(new_lower_airfoil.Ma < (Ma+Ma_delta) & new_lower_airfoil.Ma > (Ma-Ma_delta) & new_lower_airfoil.CL_res < (C_l+cl_delta) & new_lower_airfoil.CL_res > (C_l-cl_delta),:);
%% Interpolation of upper_airfoil
for x_c=0:Delta:1
    %% Vector with all unique Ids (muss nicht nochmal für Unterseite erstellt werden)
    DataId_unique=unique(new_upper_airfoil.AeroDataId); %könnte gespeichert werden für alle Daten
    for a=1:1:size(DataId_unique)
        %% temp table with all the information for one ID (AeroData ID is no longer needed)
        new_upper_airfoil_unique=new_upper_airfoil(new_upper_airfoil.AeroDataId==DataId_unique(a,:),2:5); % könnte später gespeichert werden
        %% try to find x/c
        FIND=new_upper_airfoil_unique(new_upper_airfoil_unique.X_C==x_c,:);    
        if(isempty(FIND))
            %% find the closest and secound closest x-coordinate and interpolate between them
            [d,sortIndex]=sort(abs(new_upper_airfoil_unique.X_C-x_c));
            closest=new_upper_airfoil_unique(sortIndex(1),:);
            secound_closest=new_upper_airfoil_unique(sortIndex(2),:);
            average=interp1([closest.X_C,secound_closest.X_C], [closest.CP,secound_closest.CP], x_c, 'linear','extrap');
            %% saved with closest Ma and Cl as they are the same as in secound closest
            Temp=[Temp;{x_c, average, closest.Ma, closest.CL_res}];
        else
            Temp=[Temp;FIND];
        end  
    end
    %% Interpolation
    cp_inter=IDW(Temp.Ma, Temp.CL_res, Temp.CP, Ma, C_l, -2, 'ng', 4);
    Temp(:,:)=[];
    %% Result
    DV(i,:)=[x_c,cp_inter];
    i=i+1; 
end
9 commentaires
  Stephen23
      
      
 le 11 Jan 2020
				"Preallocation is slower in this case."
Please upload the code that you tried.
Réponses (0)
Voir également
Catégories
				En savoir plus sur Graphics Performance dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
