Example of my code: (Actual code is very long. Could be found in edit history)
X = {'a','b','c','d'}
for i = 1:length(X)
if X(i) == 'a' %// for example
X(i)=[];
end
end
Why didn't the counter stop at 3rd iteration? It tried to continue till 4th iteration and generated the following error :
Index exceeds matrix dimensions.
But as the first element 'a' was deleted, The actual size of array has become 3 (instead of 4). Shouldn't the 'looping' be stopped after the 3rd iteration?