preallocating arrays in subscripts
3 views (last 30 days)
Show older comments
I have a very large program where, in attempt to reduce the amount of lines in the main script, I preallocate arrays in a subscript that is called on by the main script. When I do this however, matlab does not recognize the pre-allocation (matrices are underlined with the pre-allocation warning).
My question is this: Are arrays actually preallocated this way, and matlab erronesously says they are not? Or is matlab correct that pre-allocating in this fashion does not have any benefit?
0 Comments
Accepted Answer
Jonas
on 19 May 2021
Edited: Jonas
on 20 May 2021
if you preallocate using a script matlab just can't recognize from the outer script what happens in the inner script. thats why you use functions, which generate defined output variable names and which are then recognized by the outer script. so the suggestion is to convert you preallocation script to a preallocation function and then to call this functions explicitly with the preallocated variable names as output
0 Comments
More Answers (0)
See Also
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!