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)
Show older comments
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
0 Comments
Answers (1)
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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!