Simulink: Output argument is not assigned on some execution paths

110 vues (au cours des 30 derniers jours)
Luan Tristao
Luan Tristao le 14 Fév 2018
Commenté : jithin j le 12 Avr 2021
Using the code below in a MATLAB Function block makes my simulation in simulink not able to run due to these errors:
  • Output argument 'g' is not assigned on some execution paths.
  • Errors occurred during parsing of MATLAB function
function g = commutation(A,B,C,t)
if t <= 10^(-3) %Random pulse to initialize the motor rotation
g = [1,0,0,1,0,0];
end
if 10^(-3) < t <= 10^(-2)
g = [0,0,0,0,0,0]; %Set all phases off
end
%After 10 miliseconds, start the commutation
if t > 10^(-2)
if A~=B && B~=C && C~=A
if A == 1 && B == -1 % step6 to step1
g = [1,0,0,1,0,0]; % step1
end
if A == 1 && C == - 1 % step1 to step2
g = [1,0,0,0,0,1]; % step2
end
if B == 1 && C == -1 % step2 to step3
g = [0,0,1,0,0,1]; % step3
end
if B == 1 && A == -1 % step3 to step4
g = [0,1,1,0,0,0]; % step4
end
if C == 1 && A == -1 % step4 to step5
g = [0,1,0,0,1,0]; % step5
end
if C == 1 && B == -1 % step5 to step6
g = [0,0,0,1,1,0]; % step6
end
end
end
end
I basically want to get these inputs (A,B,C,t) and based on their values provide an output (g).
I'm aware that I have to add a case to cover the output "g" value in case of all the other conditions doesn't get in use. So, to fix it I tried to cover everything using else condition and also didn't work. Then, I placed a memory block getting the output "g" and feedbacking in a new input "mem" as follows the code:
function g = commutation(A,B,C,t,mem)
if t > 0
if t <= 10^(-3) %Random pulse to initialize the motor rotation
g = [1,0,0,1,0,0];
end
if 10^(-3) < t <= 10^(-2)
g = [0,0,0,0,0,0]; %Set all phases off
end
%After 10 miliseconds, start the commutation
if t > 10^(-2)
if A~=B && B~=C && C~=A
if A == 1 && B == -1 % step6 to step1
g = [1,0,0,1,0,0]; % step1
end
if A == 1 && C == - 1 % step1 to step2
g = [1,0,0,0,0,1]; % step2
end
if B == 1 && C == -1 % step2 to step3
g = [0,0,1,0,0,1]; % step3
end
if B == 1 && A == -1 % step3 to step4
g = [0,1,1,0,0,0]; % step4
end
if C == 1 && A == -1 % step4 to step5
g = [0,1,0,0,1,0]; % step5
end
if C == 1 && B == -1 % step5 to step6
g = [0,0,0,1,1,0]; % step6
end
else
g = mem;
end
end
else
g = [0,0,0,0,0,0];
end
end
As result even using memory or delay blocks, I get the same errors:
  • Output argument 'g' is not assigned on some execution paths.
  • Errors occurred during parsing of MATLAB function
If I declare something like "g = [0,0,0,0,0,0]" without being restricted by if/else's as shown below, the code works and the simulation runs. But for the entire simulation the output becomes this "g = [0,0,0,0,0,0]" value declared and the rest of code is totally ignored.
function g = commutation(A,B,C,t)
g = [0,0,0,0,0,0]
if t <= 10^(-3) %Random pulse to initialize the motor rotation
g = [1,0,0,1,0,0];
end
... rest of the code ...
end
I've seen some questions about the same problem on simulink but none of the solutions presented was able to fix my problem.

Réponses (3)

Izuchukwu Eze
Izuchukwu Eze le 9 Déc 2020
After the first line of equation; write: g=0; before continuing your codings.
I had similar experiences for days and I did so and it was debugged.
  2 commentaires
Nasim Hasanpour
Nasim Hasanpour le 23 Jan 2021
Thank you for your comment. It helped me.
jithin j
jithin j le 12 Avr 2021
Thank you so much.It helped me too.

Connectez-vous pour commenter.


Sebastian Castro
Sebastian Castro le 16 Fév 2018
As the error message states, there are some conditions that could make g never be assigned.
I can think of a few days to address this:
  • Are you maybe missing a condition that you haven't accounted for?
  • Can you add an else condition to the if t > 10^(-2) statement? I think that's where your error is stemming from.
  • Can you pre-initialize g at the very beginning to a default case, e.g., all zeros?
- Sebastian
  1 commentaire
Luan Tristao
Luan Tristao le 1 Mar 2018
Thanks for the recommendations. I actually managed to create that logic using only simulink blocks without function blocks.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 16 Fév 2018
Your code does not assign anything to g if t > 10^(-2) and A, B, and C are nan. nan ~= nan so the test for none of them equal to each other would be true, but then none of the individual tests would be true.
Your code does not assign anything to g if t > 10^(-2) and A, B, and C are not equal to each other but are not 1 or -1.
Your test
if 10^(-3) < t <= 10^(-2)
means the same thing as
if ((10^(-3) < t) <= 10^(-2))
The first part of that, 10^(-3) < t, will return either 0 (false) or 1 (true). That 0 or 1 is then tested for <= 10^(-2) . 0 <= 10^(-2) would be true, but 1 <= 10^(-2) would be false. So the overall test would evaluate to true if 10^(-3) >= t or t is nan.

Catégories

En savoir plus sur Programmatic Model Editing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by