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

2 Ansichten (letzte 30 Tage)
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 Kommentare
Walter Roberson
Walter Roberson am 11 Aug. 2022
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 am 11 Aug. 2022
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Shivam
Shivam am 2 Jan. 2024
Bearbeitet: Shivam am 3 Jan. 2024
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

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by