필터 지우기
필터 지우기

Error: Index exceeds the number of array elements

조회 수: 3 (최근 30일)
Spencer
Spencer 2023년 11월 15일
댓글: Walter Roberson 2023년 11월 15일
This is the error:
Index exceeds the number of array elements. Index must not
exceed 1.
Note: position1 and velocity1 are both 41x1 double
Error in Lab6Q5 (line 39)
position1(i) ) * (momentum_def(i+1) + momentum_def(i) ) /2;
position =xlsread(filename,'No Cylinder','D2:D42');
position1 =normalize(position);
velocity =xlsread(filename,'No Cylinder','E2:E42');
velocity1 =normalize(velocity);
total_momentum_def = 0;
momentum_def = 0;
for i = 1: size(position1,1)-1
total_momentum_def = total_momentum_def + ( position1(i+1) - ...
position1(i) ) * (momentum_def(i+1) + momentum_def(i) ) /2;
end

답변 (1개)

madhan ravi
madhan ravi 2023년 11월 15일
momentum_def was defined as a scalar before the loop but you are trying to access the second element in the first interation of the loop momentum_def(i + 1)
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 11월 15일
And since it is a scalar the next iteration momentum_def(2) would certainly not be defined, since nothing in the code is growing momentum_def

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by