MATLAB: Index exceeds matrix dimensions

indexindexexceedsmatrixmatrix manipulationmatrixdimensions

this line of code gives error. \bn
TS = traintarg(IX); traintarg{1×240, matrix} and IX{1×300, matrix} \bn
while this line does not and works fine \bn
DiS = Distr(IX); Distr{1×300, matrix} and IX{1×300, matrix}
I am not getting why this error occurs. ASAP

Best Answer

You are indexing into an array of 240 elements in the first case, 300 elements in the second case.
You haven't told us what is in IX, but even if we assume it is just integers between 1 and 300 in some arbitrary order this clearly will give an error when you index into the first array.
So I assume IX contains at least 1 value > 240
Please give details of matrix sizes and anything else relevant after (or before) the code though, don't mix them together into some strange pseudo-code, it makes it more difficult to understand what is actually code and what is just you adding information.
Related Question