필터 지우기
필터 지우기

Intreact between simulink and matlab

조회 수: 1 (최근 30일)
CHEW Yen LI
CHEW Yen LI 2021년 4월 25일
댓글: Walter Roberson 2021년 4월 25일
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에서 Event Functions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by