Array indices must be positive integers or logical values?

조회 수: 1 (최근 30일)
Chinni Sai Ram
Chinni Sai Ram 2022년 8월 6일
답변: John D'Errico 2022년 8월 6일
X=[1 2 3 4 5];for i=0:length(X) if mod(i,2)==0 f(i)=X(i); end end
  댓글 수: 1
Chinni Sai Ram
Chinni Sai Ram 2022년 8월 6일
Showing Array indices must be positive integers or logical values. where I committed error? Please tell me.

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

답변 (1개)

John D'Errico
John D'Errico 2022년 8월 6일
MATLAB does not allow an index of 0. The FIRST element of an array or vector is indexed as x(1).
In your loop, what was the range of the index i? You said
for i = 0:length(X)
So what does i start out as? (HINT: 0)
Now go back and read the first line I wrote.

카테고리

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