why do i receive "Errors occurred during parsing of MATLAB function"?

6 views (last 30 days)
This is my matlab function called in simulink:
function sgn = fcn(ierr,irif)
%#codegen
if ierr>(irif+10/100*irif+5)
for ierr=ierr:(irif-10/100*irif-5)
sgn=700;
end
else
sgn=0
end
if ierr<(irif-(10/100*irif)-5)
for ierr=ierr:(irif+10/100*irif+5)
sgn=-700;
end
else
sgn=0;
end

Accepted Answer

Jan
Jan on 3 Nov 2015
What is the purpose of this block:
for ierr = ierr:(irif-10/100*irif-5)
sgn = 700;
end
Using the same identifier as loop counter and to define the vector of loop indices is a very strange idea. But the loop is not useful at all, because sgn is overwritten multiple times with the same value.
Perhaps you want this:
function sgn = fcn(ierr,irif)
%#codegen
sgn = 0;
if ierr > (irif+10/100*irif+5)
sgn=700;
elseif ierr < (irif-(10/100*irif)-5)
sgn=-700;
end
  1 Comment
Marco  Cornero
Marco Cornero on 3 Nov 2015
the purpose is to create an adaptive bandwidth hysteresis controller. I tried with a form similar to one you have written, the problem is that i don't get an hysteresis bandwidth centered on irif, but on the up or low limits.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!