preallocating arrays in subscripts

3 visualizaciones (últimos 30 días)
Brandon
Brandon el 19 de Mayo de 2021
Editada: Jonas el 20 de Mayo de 2021
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?

Respuesta aceptada

Jonas
Jonas el 19 de Mayo de 2021
Editada: Jonas el 20 de Mayo de 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

Más respuestas (0)

Categorías

Más información sobre Performance and Memory en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by