index exceeds no of array elements

4 views (last 30 days)
Shalu Mathew
Shalu Mathew on 23 Feb 2020
Answered: Image Analyst on 23 Feb 2020
I ran a matlab code today and I recieved this error. Hope you guys can help.
BB= 4000;
UB = rand((t-q),BB);
indx = round(1+(t-q+1)*UB);
estar = ehat(indx);
Index exceeds the number of array elements (237).

Answers (1)

Image Analyst
Image Analyst on 23 Feb 2020
What about the error do you not understand? It says that the "Index exceeds the number of array elements" meaning that indx is greater than the length of ehat array which is 237. That is unless you overwrote the built-in functions rand() and round() with your own functions or variables. Take the semicolon off and see what it is:
indx = round(1+(t-q+1)*UB)
whos indx
whos ehat
estar = ehat(indx);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!