Matlab 向量 return 到多个向量

Matlab vector return to multiple vectors

num = zeros(1,freq);
den = zeros(1,freq);
for R = 1:freq
    [num(R), den(R)]=butter(4, [0.1 0.9]);
end

我认为这很微不足道,但一旦我 运行 它,我得到:

In an assignment A(I) = B, the number of elements in B and I must be the same.

我做错了什么?

你做错的是 numden 都包含多个系数:

[b,a] = butter(n,Wn) returns the transfer function coefficients of an nth-order lowpass digital Butterworth filter with normalized cutoff frequency Wn.

b,a — Transfer function coefficients row vectors

复制自 documentation

让代码正常工作的方法是将 numden 设置为矩阵或元胞数组:

num = zeros(freq,4);
den = zeros(freq,4);
for R = 1:freq
    [num(R,:), den(R,:)]=butter(4, [A(R) B(R)]); % matrix
end
for R = 1:freq
    [num{R}, den{R}]=butter(4, [A(R) B(R)]); % cell
end

矩阵可能更适合您的目的。