Why do I get "Array indices must be positive integers or logical values" error when using?

조회 수: 3 (최근 30일)
Array indices must be positive integers or logical values.
clc;
clear;
y(1)=0;
y(2)=1;
k=3.50
y=2 - 0.4 +1.2*y(k-1) -0.72*y(k-2);
stem(k,y,'linewidth',2);
grid;
xlabel('K');
k=0.49;

채택된 답변

James Tursa
James Tursa 2020년 9월 1일
편집: James Tursa 2020년 9월 1일
k is 3.5
So y(k-1) is y(2.5) and y(k-2) is y(1.5). The indexes are not positive integers, hence the error.
Maybe you meant
k = 3;
y(k) = 2 - 0.4 +1.2*y(k-1) -0.72*y(k-2);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by