Intreact between simulink and matlab

1 次查看(过去 30 天)
HI, can I known how can I call the m file from the matlab fucntion block in simulink?

回答(1 个)

Walter Roberson
Walter Roberson 2021-4-25
编辑:Walter Roberson 2021-4-25
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 个评论
CHEW Yen LI
CHEW Yen LI 2021-4-25
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 2021-4-25
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Model Verification 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by