Error with butter function "Index exceeds the number of array elements. Index must not exceed 2."

조회 수: 2 (최근 30일)
Hi, could any one please help me?
I have matlab R2022a an I am trying to use the function butter, this is my code
fc = 300;
fs = 1000;
[b,a] = butter(6,fc/(fs/2));
and matlab shows this message error
Index exceeds the number of array elements. Index must not exceed 2.
Error in zp2ss (line 185)
a1 = t\[-den(2) -den(3); ONE ZERO]*t;
Error in butter>butterImpl (line 103)
[a,b,c,d] = zp2ss(zs,ps,ks);
Error in butter (line 59)
[varargout{1:nargout}] = butterImpl(n,Wn,varargin{:});
Thanks!!!
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 8월 11일
Odd, that would tend to imply that the worker function buttap(6) returned a vector of length 2 instead of a vector of length 6. I cannot see anything in the code that could lead to that situation.
Erick Guzman
Erick Guzman 2022년 8월 11일
Hi @Walter Roberson this example code is from the mathworks and when I run the code in MATLAB online it works well.
I think that is something else.

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

답변 (1개)

Shivam
Shivam 2024년 1월 2일
편집: Shivam 2024년 1월 3일
Hi,
From the information provided, I understand that while trying to design a 6th-order lowpass Butterworth filter, you are getting an index-exceeding error in MATLAB R2022a. However, you have noted that this issue does not occur when running the same example in MATLAB online.
I tried the same example from the 'butter' function in MATLAB's help files on MATLAB R2022a, and it worked perfectly without throwing any errors. It produces arrays 'a' and 'b' each of size 1x7:
b = [0.0701 0.4207 1.0517 1.4023 1.0517 0.4207 0.0701]
a = [1.0000 1.1876 1.3052 0.6743 0.2635 0.0518 0.0050]
You can try the following possible workarounds to get over the issue:
  • Restart MATLAB and rerun the code.
  • Reinstall the Signal Processing toolbox.
Please refer to the following documentation to know more about the 'butter' function: https://www.mathworks.com/help/releases/R2023b/signal/ref/butter.html
I hope it resolves the issue.
Thanks

카테고리

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