필터 지우기
필터 지우기

Array indicates must be positive integers or logical values

조회 수: 2 (최근 30일)
Hoang
Hoang 2022년 12월 29일
답변: Kunal Kandhari 2023년 1월 17일
h=input('Number of subinterval: ');
sum=0;
for i=1:1:h-1
y(i)=input('List of numbers: ');
sum=sum+y(i);
end
answer=h/2+(y(0)+y(h)+2*sum);
disp(double(answer));
When I list my numbers in the y(i), the maximum number that I can type is 7 and then it shows the error "Array indicates must be positive integers or logical values". Anyone know how to fix this please help me

답변 (1개)

Kunal Kandhari
Kunal Kandhari 2023년 1월 17일
Hi,
Matlab Array indices start from 1.
Since you are using taking h as input and runnng loop till h-1 so both of following doesn't contains any value
y(0) and y(h)
As indices starts from 1 so h(0) isn't a valid input and you have taken input till h-1 so y(h) dosen't has any value.
Hence, you get error: Array indices must be positive integers or logical values.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by