Is output, internally cleared before executing the next loop?
No. A variable is only cleared if
- you assign something else to it. The clearing occur at the point where the assignment occurs and only then.
- it goes out of scope (e.g. a variable created inside a function is cleared when the function ends)
- you explicitly clear it
Anything else would make no sense and break a lot of code.
I have inserted a 'clear output' between line 1 and 2, and expect script to run without memory error
If someCalculation does create a GB sized output, then yes it will make some difference. The previous content of output gets cleared when you assign the new result of someCalculation and only then. So, while someCalculation is running, with its own internal variable that takes GB of memory, you also have the previous content of output sill in memory. Rather than clear I'd recommend setting output to [].
while creating output for ith iteration, is the size of output from i-1 th iteration a bottleneck in terms of memory?
Only when someCalculation is being executed.
Of course, all this assumes that you haven't made any copy of output. Otherwise, these copies still take some memory.
댓글 수: 1
이 댓글에 대한 바로 가기 링크
https://kr.mathworks.com/matlabcentral/answers/462273-while-assigning-a-variable-is-the-variable-cleared-by-default-before-the-assignment#comment_705461
이 댓글에 대한 바로 가기 링크
https://kr.mathworks.com/matlabcentral/answers/462273-while-assigning-a-variable-is-the-variable-cleared-by-default-before-the-assignment#comment_705461
댓글을 달려면 로그인하십시오.