I have an array that increases in size in a loop. the solution for that in matlab is pre-allocation with zeros using x = zeros(1, 9);
my problem is that sometimes the array will have some zeros at the start and at the end of the array. those zeros are part of my data. and I need to work with the array when it’s size is 5,later when it’s 7, and finally when it has 9 elements.
How do I work with them without confusing em with the pre-allocation zeros?
UPDATE
The use of NANs is the easiest way, it worked well for me. altho Prashant posted a more complex solution that will work well for other requirements. (my function is quite simple.)
The easiest way is to pre-allocate it to
NaNYou can also just make sure that the rest of your code keeps track of your indexes, but
NaNs are awfully easy.