Subscript indices must either be real positive integers or logicals.
1 view (last 30 days)
I get this error ,
Subscript indices must either be real positive integers or logicals. The line with this error is,
Error in motionComp (line 34)
Please help me in resolving this error and thanks in advance.
Adam on 22 Sep 2014
If your values to be used as indices into an array are the result of some calculation, especially one which uses division, multiplication and really anything more complex than addition and subtraction you should use:
idx = round(idx);
for an index value, idx, or just put round(idx) straight into the indexing line if you prefer.
If you are confident you should never get floating point-based index inaccuracies then you can, of course, leave that off, but if you cannot be sure of every conceivable output of your function that creates idx then this is best to ensure a valid index value.