How to solve this error : "index out of bounds because numel(U)=1"
2 views (last 30 days)
I know this question has been answered a housand times, but no solution I could find seemed to work, so this is my last resort.
Complete Error : Attempted to access U(1001); index out of bounds because numel(U)=1. Error in Identifiant>identifier (line 92) K=Y(i)/U(i);
function identifier (Y,U,Pr)
while (b-a<Pr && i<length(Y))
Here is the function where the error seems to be.
And the definition of Y and U is as follows :
I understood that U has no 1001st element, because it doesn't have the same size as Y. I tried to put both as vectors, but of course it does nothing. I also tried to use the function reshape, but it doesn't seem to work either or I might be using it wrong.
Anyways if anybody has any idea on how to solve this issue i'd be glad to listen to it. Thank you!
Jon on 22 Nov 2021
With your definition of U, U has only one element. Note you first assign a scalar (one element) variable u=1, then you assign U to equal every element U = u(:) of u, but it only has one element, so now U also has only one element. So it doesn't make sense to ask for elements with indices greater than 1.