How can i speed up my function?

1 visualización (últimos 30 días)
Gerrit
Gerrit el 8 de En. de 2020
Comentada: Gerrit el 12 de En. de 2020
Hello everybody,
I'm trying to increase the performance of my Matlab function. Input is a table with the same columns as airfoil_update.
The function splits the X-Coordinates of one AeroDataId at the minimum of X/C and does this for every AeroDataId in the table. Airfoil, the input table, will have a size of 131123421x4. But the fourth column "Upper" is empty and should be filled up with a 1, if the coordinate belongs to the upper airfoil and 0, if it belongs to the lower airfoil.
Thank you very much in advance.
function [airfoil_update] = splitAirfoil(airfoil)
%% create table for upper and lower airfoil
airfoil_update=array2table(zeros(0,4),'VariableNames',{'AeroDataId','X_C','CP','Upper'});
%% vector with unique AeroDataIds
DataId_unique=unique(airfoil.AeroDataId);
for i=1:1:size(DataId_unique)
%% temp vector filled with every point of specific AeroDataId
disp(DataId_unique(i,:));
AeroDataId=airfoil(airfoil.AeroDataId==DataId_unique(i,:),:);
%% find the minimum of X/C
[~, min_idx]=min(AeroDataId.X_C);
%% every point with same ID before minimum -> lower_airfoil -> Upper =0
airfoil_new=AeroDataId(1:min_idx,:);
airfoil_new.Upper(:,:)=0;
airfoil_update=[airfoil_update; airfoil_new];
%% every point with same ID after minimum = upper_airfoil -> Upper =1
airfoil_new=AeroDataId(min_idx+1:end,:);
airfoil_new.Upper(:,:)=1;
%% add new rows
airfoil_update=[airfoil_update; airfoil_new];
end
end
  4 comentarios
Daniel Ribeiro Gonçalves
Daniel Ribeiro Gonçalves el 9 de En. de 2020
They wont be deleted.. Its only for the matter of performance.. It will lower your program computacional time
Gerrit
Gerrit el 9 de En. de 2020
Editada: Gerrit el 9 de En. de 2020
Oh okay I understand. But where would I put it?
And I just saw sparse does not work for tables.

Iniciar sesión para comentar.

Respuesta aceptada

Philippe Lebel
Philippe Lebel el 8 de En. de 2020
Editada: Philippe Lebel el 8 de En. de 2020
In order to help you in a significant way, it would be useful to have a sample data set on which we could run the function.
On the top of my head, i'd remove the disp() function call. Printing info to the console takes a significant amount of time for no real benefit.
I would also pre-alocate the size of
airfoil_update
since you know it's maximum size, you can pre alocate it to that size and keep track of the number of elements you put in it then chop the unused space only once at the end of the script.
  9 comentarios
Gerrit
Gerrit el 9 de En. de 2020
Thank you veryyy much Philippe!!
here is the link: https://de.mathworks.com/matlabcentral/answers/499639-how-can-i-speed-up-my-code
Gerrit
Gerrit el 12 de En. de 2020
Philippe, do you have any idea for my other problem?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by