It sounds very much like end-(int8(i)-1)
ends up reaching zero or below. Check what is the value of i
when you get the error and compare this to how many columns eigvecm
has.
BTW if you want the eigen vecotr corresponding to the ith largest eigen value how about this:
[vec, val] = eig(M);
[~, ind] = sort(diag(val), 'descend');
ind(i)
is the column number for the ith largest eigen value. So to find the corresponding eigen vector:
vec_i = vec(:, ind(i));