
Why do i get "Index exceeds the number of array elements (2)". and how can i fix it? Please
2 ビュー (過去 30 日間)
古いコメントを表示
Josué Cartujano Barrera
2020 年 9 月 1 日
編集済み: Abdolkarim Mohammadi
2020 年 9 月 1 日
clc;
clear;
y(1)=0;
close all;
y(2)=1;
k=3:50
y(k)=2 -0.4 +1.2*y(k-1) -0.72*y(k-2);
stem(k,y,'linewidth',2);
grid;
xlabel('K');
k=0.49;
ylabel('y(k)');
0 件のコメント
採用された回答
Abdolkarim Mohammadi
2020 年 9 月 1 日
編集済み: Abdolkarim Mohammadi
2020 年 9 月 1 日
You should first initialize the variable y. I also changed the definition order of the elements of y. I didn't understand why you assigned the value of 0.49 to k at the end of the code?!
clc;
clear;
close all;
k=3:50
y = zeros(numel(k)); % initialize variable y with the same length as k
y(1)=0; % assign values after initialization
y(2)=1; % assign values after initialization
y(k)=2 -0.4 +1.2*y(k-1) -0.72*y(k-2);
stem(k,y,'linewidth',2);
grid;
xlabel('K');
% k=0.49;
ylabel('y(k)');

その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!