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