Undefined function or variable?

2 次查看(过去 30 天)
I have this code any problema than you can find?: I'm using MatlabFcn in simulink
function out = fcn(qp, tao)
fc=8.955;
fv=5.234;
fs=18.617;
vs=0.145;
delv=1.032;
delt=0.172;
ts=0.888;
fk=(fc*sign(qp))+(fv*qp);
if qp == 0 && abs(tao)< fs
fq= tao
end
if qp == 0 && abs(tao)>= fs
fq=fs*sign(tao)
end
if qp ~= 0
fq=fk
end
out = fq;
But even when "fq" has a value always. I can't play the program.
Undefined function or variable 'out'. The first assignment to a local variable determines its class.
Function 'ImpovedStaticCoulombViscous' (#133.132.135), line 10, column 4: "out" Launch diagnostic report.

采纳的回答

Walter Roberson
Walter Roberson 2016-2-29
Your code does not define fq in the case that qp is nan.
When you are constructing MATLAB Function blocks, it is safest to start by assigning the output zeros() of the appropriate size and data type.
I also recommend that you code as
if qp == 0
if abs(tao)< fs
fq = fs;
else
fq = fs * sign(tao);
end
else
fq = fk;
end
this makes it obvious to the compiler that fq is assigned in every possible branch. (But give some thought to handling nan anyhow.)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Filter Design and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by