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
preallocating arrays in subscripts
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!