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
채택된 답변
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
추가 답변 (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!