Intreact between simulink and matlab

1 visualización (últimos 30 días)
CHEW Yen LI
CHEW Yen LI el 25 de Abr. de 2021
Comentada: Walter Roberson el 25 de Abr. de 2021
HI, can I known how can I call the m file from the matlab fucntion block in simulink?

Respuestas (1)

Walter Roberson
Walter Roberson el 25 de Abr. de 2021
Editada: Walter Roberson el 25 de Abr. de 2021
The usual way: just name the function and pass in any appropriate arguments. Simulink will search for functions with that name along the MATLAB path.
If the question is how you can tell at MATLAB Function Block to use a particular file as the code to be executed, instead of typing in the code to the block editor, then the answer is that you cannot do that. The source code for MATLAB Function Blocks is stored inside the model. However, you can use a MATLAB Function Block that does nothing other than initialize the output variables (so it knows the types and sizes), and then call the MATLAB function to do the real work.
  2 comentarios
CHEW Yen LI
CHEW Yen LI el 25 de Abr. de 2021
you mean that I cannot run a m file in the matlab function block? because I want to run the linearprogamming on the matlab function block.But there is a error when i run it. So i plan to type the scipt on the matlab. then at matlab function block call the scipt. but i do no this action can be done ? the code below is the code that I try right now.
function v = SRG1( v_previous, r)
%#codegen
coder.extrinsic('linprog','optimoptions');
f=-1;
A=[];
b=[];
Aeq=r-v_previous;
beq=v(1)-v_previous;
lb=0;
ub=1;
options=optimoptions('linprog','Algorithm','interior-point');
k=linprog(f,A,b,Aeq,beq,lb,ub,options);
v= v_previous + k*(r - v_previous);
end
the above code is refer to below
max k
(k∈[0,1])⁡
subject to v(t) = v (t − 1) + κ(r(t) − v (t − 1))
where v(t) is the output of the reference governor,
r(t) is the reference input,
v(t-1) is the previous output of the reference governor
hope can get some help from you
Walter Roberson
Walter Roberson el 25 de Abr. de 2021
What is the error message that you observe?
You only have a single variable, that can only take the values 0 and 1, and you have a linear equality. You do not need intlinprog for this purpose; you can calculate the two possibilities directly.

Iniciar sesión para comentar.

Categorías

Más información sobre Model Verification en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by