Simulink user defined block

조회 수: 2 (최근 30일)
Srikanth
Srikanth 2012년 3월 28일
I wanted to calculate the average of a particular array recursively, I am using this code shown below and I am using the user defined function on simulink to do this. I am getting the out of bounds error while i run the simulation, and when i debug, the averaging formula shown below is the problem. What could the reason be, although i feel like its a simple mistake that i am making
function poutavg = fcn(pout)
tstop=2*10^-3;
fsamp=4000000;
for i=2:tstop*fsamp
poutavg =((i-1)/i)*mean(pout(1,i-1))+ (pout(1,i))/i;
i=i+1;
end
  댓글 수: 1
K E
K E 2012년 3월 28일
When I run this in Matlab it works fine, as long as length(pout) >= length(2:tstop*fsamp). So, check that the dimensions of pout are what you would expect.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by