Could not determine the size of this expression

4 次查看(过去 30 天)
I want to convert the LMS filter algorithm to Verilog, but need to solve the problem of variable matrix. The point is, why does MATLAB think this piece of code is mutable? How can I solve this problem?
Verilog does not Support mutable matrices, so I uncheck Support variable_size arrays.
function [yn,W,en]=LMS(xn,dn,M,mu)
itr = length(xn);
en = zeros(itr,1);
W = zeros(20,100);
for k = M:itr
x = xn(k:-1:k-M+1);
y = W(:,k-1).' * x;
en(k) = dn(k) - y ;
W(:,k) = W(:,k-1) + 2*mu*en(k)*x;
end
yn = inf * ones(size(xn));
for k = M:length(xn)
x = xn(k:-1:k-M+1);
yn(k) = W(:,end).'* x;
end
could not determine the size of this expression. Function 'LMS/MATLAB Function' (#90.543.553), line 19, column 12: "k:-1:k-M+1" Launch diagnostic report.
  4 个评论
Fangjun Jiang
Fangjun Jiang 2023-5-10
编辑:Fangjun Jiang 2023-5-10
This is a MATLAB Function block in Simulink. M is an input to the MATLAB Function block. At each simulation step, M could change, thus the size of x could change.
Does M change value during the simulation?
Walter Roberson
Walter Roberson 2023-5-10
Odd... I only count 17 lines of code, but the error is on line 19. (I was trying to determine if the error was on the first assignment to x or the second assignment.)
If the error was on the second assignment, then maybe it might go away if you use a different variable instead of x in the second loop, so that it does not see the second loop as a redefinition of x.
It looks to me as if the two loops could be merged. The first loop is M:itr but iter = length(xn), so when the second loop is M:length(xn) that is really the same upper bound -- it is confusing that itr was not used there as well.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by