Getting error "Output argument 'y' is not assigned on some execution paths" Trying tp generate pwm for duty cyle value coming from a PI controller for converter control

1 view (last 30 days)
So guys im trying to generate PWM by using while loop. The reason im doing so is that the other blocks in matlab are not functioning as I want. Im attaching my code below, for which im getting simulation errors, one of which is mentioned in the title.
error: Output argument 'y' is not assigned on some execution paths

Answers (1)

Sabin
Sabin on 30 Jan 2023
As there is a possibility to not enter the while statement, the solver will think that ‘y’ might not be assigned any value in the first branch. The code can be rewritten in a slightly different way as below. This code will run but can be further optimezed probably depending on the requirements.
function y = fcn(u)
a = 50000;
r = u*a;
count = 0;
if r < a
y = 0;
while count < a
if count <= r
y = 10;
end
count = count + 1;
end
else
y = 0;
end

Community Treasure Hunt

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

Start Hunting!