Search code examples
matlabfunctioncode-generationsimulink

If Statement Matlab Function on Simulink


I am trying to made my own Matlab function to use in Simulink but I have not success. It is a simple If statement with one input and three output values,all of them integer, here the code:

function [ PWM,INA,INB ]  = VNH5019(in_Motor)
if in_Motor ==0
   INA=0;
   INB=0;
   PWM=0;
elseif in_Motor>0
    if in_Motor>255
    in_motor=255;
    end
      INA=1;
      INB=0;
      PWM=in_Motor;
elseif in_Motor<0
   if  in_Motor<-255
       in_motor=-255;
   end
   INA=0;
   INB=1;
   PWM=-in_Motor;
end

And here the error:

Output argument 'PWM' is not assigned on some execution paths.

Function 'MATLAB Function' (#38.28.35), line 1, column 29:
"VNH5019"

Solution

  • You should probably replace that line:

    elseif in_Motor<0
    

    with a simple else.