MATLAB Answers

Code Slows Down if I Preallocate Larger Variables?

1 view (last 30 days)
Alessandro on 16 Jun 2015
Commented: Alessandro on 17 Jun 2015
Hello, I am using Matlab to explicitly integrate equations of motion for a finite element mesh. In the code I initialise all the history variables (such as displacement, velocity and acceleration) to store all the values at every node for every time step.
displace = zeros(gdl,n_inc+1); %
epsilon = zeros(gdl,n_inc+1); %
stress = zeros(gdl,n_inc+1); %
The point is: if I use a larger number of time steps (i.e. a smaller time increment), every single step takes much more to run. Is that avoidable somehow?


Show 4 older comments
Adam on 16 Jun 2015
That depends on how the algorithm is coded. The profiler should tell you where the time is being spent.
profile on
...your code here...
profile off
profile viewer

Sign in to comment.

Answers (0)