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 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Sabin
2023-1-30
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!