The error means you are trying to access an element in Q that does not exist. From the message, Q contains 8 elements, so you get an error when trying to indext a 9th element.
This makes sense. You define Q as having 8 elements.
Q = [beta alpha lambda vac d gamma c m];
but in your function, you try to access a 9th element