You can try iterate in reverse order to avoid the warning:
for ei=length(E):-1:1,
hnds(ei) = plot(1:nP, avgR(ei,:), [clrStr(ei),'-'] );
end
In this case you do not need to pre-allocate (i.e., no hnds = zeros(1,length(E));
).
By iterating in reverse order, the array size hnds
is determined in the first iteration and stays fixed throughout the iterations.
See this thread for more information.