Set initial value in Matlab Function block

조회 수: 52 (최근 30일)
William
William 2014년 4월 17일
답변: Danilo Teran 2018년 12월 4일
How can I set the initial value for UP? UPI is my initial value input to the block. How can I make sure UP will accepts thhs value only once (start of the simulation)? Thanks
funciton UP=[UPI]
*UP=UPI;
%#close safety_relieve_valve
SRV=0;
if (UP>UL)
Val=0;
UP=RD;
else
Val=1;
UP=RU;
end
if (UP<LL) & (Val==0)
UP=RD+0.1;
disp(UP);
Val=1;
elseif (UP>=LL) & (Val==1)
UP=UP+0.1;
end*
  댓글 수: 5
Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 17일
have you tried Ports and Data Manager?
William
William 2014년 4월 17일
The input is set as Inherit: same as Simulink. I kept getting error "Expecting scalr...." I changed the type to "double" but no avail.

댓글을 달려면 로그인하십시오.

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 17일
편집: Azzi Abdelmalek 2014년 4월 17일
You can use persistent declaration
function UP=fcn(UPI)
persistent UPI1
if isempty(UPI1)
UP=UPI
else
UP=UPI1
end
%your code
UPI1=UP;
  댓글 수: 11
William
William 2014년 4월 17일
Instead of using the 'elseif' statement, I created another 'if' statement & it worked. But there are some other issues I would like to resolve. I will post it later. Thanks again.
William
William 2014년 5월 19일
편집: Azzi Abdelmalek 2014년 5월 19일
function UP = UPC(t,LL,u1,u2,u3,u4,u5,u6,u7,u8)
%#codegen
persistent LLI
if isempty(LLI)
UP=LL;
else
UP=LLI;
end
My code
LLI=UP;
Azzi, I kept getting the error message "LLI is not defined..." when I attempted to run the simulation. "LL" is my IC for UP. Any idea? Thanks.

댓글을 달려면 로그인하십시오.


Danilo Teran
Danilo Teran 2018년 12월 4일
Hi
I have a similar problem, could you find a real solution.
Best regards?

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by