Is there any ways that I can preallocate the unknown sized array or matirx?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Wai Han
am 7 Okt. 2020
Kommentiert: Wai Han
am 8 Okt. 2020
I Just want to know if I can make a preallocate array.
Please also explain me how much difference is there between the preallocated program and the unpreallocated one.. (for a small program).
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 7 Okt. 2020
Bearbeitet: Ameer Hamza
am 7 Okt. 2020
Pre-allocation will make a huge difference if your array size is very large. See a comparison here: https://www.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html. That being said, for a small array size, you might not notice a considerable difference. However, as a general principle, pre-allocation is a good idea. If the array size is unknown initially, you can do incremental growth of the array. This FEX package by John: https://www.mathworks.com/matlabcentral/fileexchange/8334-incremental-growth-of-an-array-revisited has an excellent implementation of incremental pre-allocation. You can directly use it in your project.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!