why do i recive Index in position 2 is invalid. Array indices must be positive integers or logical values
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi every one
i have tried to implement for loop in order to compute the model the idea is how can i compute this model at the first iteration then i have to compute it again in the folloing iteration
u=[p;s;c] this is the u column vector of my model with 153*1 dimension where p,s,c 51*1
iteration =10;
iteration(:,1)=u(:) here i would like to say that at first iteration compute the model from p,s,c inputs but i have got the error meassage as titled in the question so how can i do that
this is what iam trying to do
for i =1:iteration
[unkown, unknown,unknown ]=function([u(1),u(2),u(3)])
iteration(:,i+1)=u(:) here i want to increase the iteration counter
end
so how can i do
thank you
댓글 수: 1
hamza karim
2021년 10월 26일
I coudn't really understand your question but your code is quite odd.
first you are defining iteration as a scalar. Then by writing
iteration(:,1)=u(:)
you are simply overwritting your initial value of 10, here you would have iteration as a vector of size 153x1 as per your u vector.
then when you are writing your for loop, you say
for i=1:iteration
end
this does not make sense. If your objective is to make 10 iteration you simply write
for i=1:10
end
and if the iteration is as per your u vector size then
for i=1:length(u)
end
as your code is written
at the ligne
iteration(:,i+1)=u(:)
is as you are saying iteration(:,2)=u(:) which is impossible since iteration is initially a vector of size 153x1
답변 (1개)
Cris LaPierre
2021년 10월 26일
This error means that you are not using integer values to index your array. Position 2 indicates it is your column index that is incorrect.
A=rand(2);
% works
A(1,2)
% doesn't work
A(1,1.5)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!