overwrite cell array in a loop
13 views (last 30 days)
the code is given below; parts(day) are calculated using some data which is let say comes out as 3 4 2 for day 1 2 3. complete code is attached in file.. when the value of parts(day) decreses from previous loop, the cell cannot reassign the new value but overwrite on previous and causes extra cell which creates error in reshaping.
n = 2;
Stephen23 on 31 Jul 2018
Edited: Stephen23 on 31 Jul 2018
clear the cell array before you implicitly create it with that allocation:
Note that this is not an efficient solution. A much better solution would be to explicitly create the cell array of the right size each time, e.g.:
P = cell(1,4);
P = cell(1,2);
I recommend that you explicitly create the cell array.