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?

采纳的回答

Jonas
Jonas 2021-5-19
编辑:Jonas 2021-5-20
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 个)

类别

Help CenterFile Exchange 中查找有关 Performance and Memory 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by