simulink error
3 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have a simulink error : "Error in 'model/S-Function' while executing MATLAB S-function 'polinomf', flag = 1 (derivatives), at time 0.0." and do not know anythink about it. Can someone help me? This is the code:
function [sys, x0] = simulink(t,x,u,flag)
if flag == 0
sys = [1 0 1 2 0 0];
x0 = [1];
TS = [-1 0];
elseif flag == 1
Ka=10^-4.75;
Kw=10^-14;
w=Xb-Xa;
w1=Ka*w;
z=-Kw*Ka;
y=w1-Kw;
x=Ka+Xb;
p=[1 x y z];
n=roots(p);
if n(1)>0 r=n(1);
else if n(2)>0 r=n(2);
else r=n(3);
end
end
ph=-log10(r);
pH=ph';
sys = pH;
elseif flag == 3
sys = x;
else
sys = [];
end
Thank you
0 件のコメント
採用された回答
Walter Roberson
2011 年 9 月 29 日
In the case where flag == 1, your code calculates
w=Xb-Xa;
but neither Xb nor Xa are defined. This causes MATLAB to error() out.
You do use w, so you will have to figure out how to set Xb and Xa.
2 件のコメント
Walter Roberson
2011 年 9 月 29 日
Every function has its own workspace. Xa and Xb have not been defined in the workspace of the function.
If the values were defined before the simulation in the base workspace, and either you have used a "From Workspace" block to get them in to the simulation (and do not change them) or you do not otherwise use them in the simulation, then you can import the value you need from the base workspace using
w = evalin('base','Xb - Xa');
However, if you _are_ importing them in to Simulink from the base workspace, or if you calculate them in Simulink or if you modify them in Simulink, then it would be better to connect those values to become inputs to the S function.
その他の回答 (1 件)
Fangjun Jiang
2011 年 9 月 29 日
Why do you define your function as "simulink"? It sounds like you are using the Simulink toolbox if you are talking about S-function. Should it cause confusion or even problem?
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Sources についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!