simulink error
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Walter Roberson
el 29 de Sept. de 2011
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 comentarios
Walter Roberson
el 29 de Sept. de 2011
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.
Más respuestas (1)
Fangjun Jiang
el 29 de Sept. de 2011
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 comentarios
Ver también
Categorías
Más información sobre Sources en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!