Simulink user defined function: undefined variable or function

3 ビュー (過去 30 日間)
Martijn
Martijn 2012 年 6 月 10 日
コメント済み: Sumukh Bharadwaj 2018 年 3 月 21 日
Dear all,
When using a user defined Matlab function in Simulink, with the following structure:
function xdot = fcn(x,u)
%VEHICLE PROPERTIES (removed here)
%%Dea
xdot(1)=V*cos(x(1));
xdot(2)=V*sin(x(1));
xdot(3)=V*1/l(1)*tan(u);
xdot(4)=-xdot(3)-V/l(2)*sin(x(4))-xdot(3)*(c(1)/l(2))*cos(x(4));
V(1)=V;
for k=2:n-1
ratep=xdot(3)+sum(xdot(4:k+2)); %yaw-rate precessing unit
V(k)=V(k-1)*cos(x(k+2))-ratep*c(k-1)*sin(x(k+2)); %velocity precessing unit
xdot(k+3)=-ratep-V(k)/l(k+1)*sin(x(k+3))-ratep*(c(k)/l(k+1))*cos(x(k+3));
end
end
I get the errors: Undefined function or variable 'xdot'. The first assignment to a local variable determines its class.
As you can see, I want to assign a value to xdot, so I do not understand where the error comes from. Can anyone help?

採用された回答

Walter Roberson
Walter Roberson 2012 年 6 月 11 日
Start the routine with
xdot = zeros(1, n+2);
  2 件のコメント
Martijn
Martijn 2012 年 6 月 11 日
Thank you, the function variable are not allowed to change size to be able to generate code.
Sumukh Bharadwaj
Sumukh Bharadwaj 2018 年 3 月 21 日
Hi,
I'm facing the same problem! "Undefined function and first assignment........
How did you overcome it?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by