While assigning a variable, is the variable cleared by default before the assignment?
Show older comments
Hello all,
please clarify my doubt regarding variable assignment in MATLAB.
say
for iLoop=1:100%Line_1
output=someCalculation(iLoop);%Line_2
someOtherCalculation(output);%Line_3
...
...
end%Line_n
In line 2, we can see that output is written with value from someCalculation(). Is output, internally cleared before executing the next loop?
The background of my question is, one of our scripts (I realise scripts are bad. But legacy scripts), was creating a variable 'output' - (quite a huge variable - 1000s of MBytes) in every iteration.
In one of the iteration, there was memory error in Line 2. I have inserted a 'clear output' between line 1 and 2, and expect script to run without memory error.
Is my expectation correct?
In other words, while creating output for ith iteration, is the size of output from i-1 th iteration a bottleneck in terms of memory?
1 Comment
Rik
on 15 May 2019
Shouldn't you be able to check this by creating an array that should fill most of your memory and comparing the results of running it with and without a clear statement?
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!