How to delete an element from an array, which is in looping ?
Following is a psuedo-code example of what I am trying to do. I loop over an array and delete elements bas开发者_运维技巧ed on a condition. Now the problem is when I remove the elements the size of myArray is changing, and I get an out of index exception. Any ideas on how to get around this?
for i = 1:size(myArray)
if myArray(i) == someValue
remove_from(myArray, i)
a simple solution for this problem is loop from the last to the first element.
for i = size(myArray):1
if myArray(i) == someValue
remove_from(myArray, i)
精彩评论