필터 지우기
필터 지우기

simulink error

조회 수: 3 (최근 30일)
Cosmin Darab
Cosmin Darab 2011년 9월 29일
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

채택된 답변

Walter Roberson
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
Cosmin Darab
Cosmin Darab 2011년 9월 29일
thank you for answer
is it not ok that Xb and Xa are defined in workspace?
Walter Roberson
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
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?

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by