Speed up code - deletion of rows/columns
7 views (last 30 days)
Show older comments
In my code I have a lot of big sized variables. In order for the code to run on my computer, I decided on deleting already assigned (and further processed, thus not anymore needed) rows / columns.
velocity_air(:,:,2) = [];
transformation_matrix(:,:,:,:,2) = [];
It seems to me, that by doing this, I succeed in reducing the required RAM, however those deleting assignments take a lot of time. In fact, the time increases exponentially when I increase the number of iterations.
Is there another way to delete used rows / columns?
What else can I do to have the code run faster?
2 Comments
KSSV
on 25 Aug 2020
Check squeeze once. First you need to think why those many dimensions in matrix?
Answers (2)
Steven Lord
on 25 Aug 2020
I'm guessing you're doing this in a loop. In that case consider the old song 99 Bottles of Beer, slightly modified.
99 bottles of beer on the wall, 99 bottles of beer
Take one down, pass it around, slide all the other bottles forward to fill the slot, 98 bottles of beer on the wall
Doesn't quite have the same ring to it, does it? And you're going to be sliding all the bottles forward a lot. How often does that 99th bottle move? That's kind of what you're doing when you delete a page from the middle of the array.
How big are these "big sized variables"? How much memory does the system on which you're running your code have?
Mir Amid Hashemi
on 28 Sep 2020
I had a similar problem, however I don't know if it can be applied to your code. I created a fifo of constant length in the gpu. Whenever I considered one element of the fifo to have processed, I gather it to CPU ram and use that index to put a new element. What you might be doing is changing the dimension of your matrix dynamically and it slows performance.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!