How can i hold on output to run a matlab function with it during simulation ?

조회 수: 7 (최근 30일)
I have an output of a model in simulation a voltage(rectangular) and i need it as in input in a matlab function with in the simulation model to run , how do i store it ? i tried a buffer an zero holder but i cant store or hold on all the values
  댓글 수: 3
K G
K G 2019년 7월 18일
during the simulation , i need the values of 7 seconds of the 10 seconds simulation time
K G
K G 2019년 7월 19일
want to store my values while simulation running under a condition to use it before the simulation time end. I only need values in my vector and no 'nan' because i need to do a calculation on it.
function u_out = fcn(statusFlag,u_in)
u_out=zeros(100000,1);
persistent n
if isempty(n)
n = 0;
end
n=n+1;
persistent u_data
if isempty(u_data)
u_data = 0;
end
if statusFlag == 4
u_data=u_in;
u_out(n+1)=u_data;
elseif statusFlag~=4 && statusFlag~=5
u_data=nan;
end
end

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

채택된 답변

Samatha Aleti
Samatha Aleti 2019년 8월 2일
Hi,
According to my understanding you want to store the output of each step simulation and want to access it in MATLAB Function block during the simulation. One of the ways you can do is to connect the Output with a delay block as one of the inputs to MATLAB function block and use persistent vector in MATLAB function to store each output.
If the MATLAB function has to perform functions based on simulation time, you can use clock block in SIMULINK model.
You can refer the attached model and MATLAB function as an example.
function y = fcn(~, data)
persistent CP
if(isempty(CP))
CP = 0;
else
CP = [CP data];
end
y = CP(end);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by