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

2 vues (au cours des 30 derniers jours)
Federico Lusardi
Federico Lusardi le 19 Mar 2021
i'm having this error in matlab function block, referred to the code below: some previously topic help me in check every IF-ELSEIF-ELSE paths and i think V_cv is defined for every cicle. what can be the mistake? I Can't do debugging 'cause the error stops simulink in the calling of this function
COMPLETE ERROR MESSAGE: Output argument 'V_cv' is not assigned on some execution paths.
Function 'MATLAB Function2' (#24.10.14), line 1, column 11:
"V_cv"
Launch diagnostic report.
function [V_cv, ga1, ga2, ga3, gb1, gb2, gb3, gc1, gc2, gc3] = fcn(SOCA, SOCB, SOCC)
V_Ilim=0.8;
persistent R
R=[];
if isempty(R)==1
R=0;
end
if R==0
V_cv=0;
ga1=[0 0 0 0];
ga2=[0 0 0 0];
ga3=[0 0 0 0];
gb1=[0 0 0 0];
gb2=[0 0 0 0];
gb3=[0 0 0 0];
gc1=[0 0 0 0];
gc2=[0 0 0 0];
gc3=[0 0 0 0];
end
%% CV
%condition 1
if all(SOCA>=V_Ilim)
R=1;
V_cv=Vocp_function(SOCA(1));
end
%condition 2
if all(SOCB>=V_Ilim)
R=2;
V_cv=0;
end
%condition 3
if all(SOCC>=V_Ilim)
R=3;
V_cv=0;
end
if R==1
if SOCB(1)<=V_Ilim || SOCC(1)<=V_Ilim
V_cv=Vocp_function(SOCA(1));
ga1=[1 0 0 1];
ga2=[1 0 1 0];
ga3=[1 0 1 0];
gb1=[1 0 0 1];
gb2=[1 0 1 0];
gb3=[1 0 1 0];
gc1=[1 0 0 1];
gc2=[1 0 1 0];
gc3=[1 0 1 0];
elseif SOCB(2)<=V_Ilim || SOCC(2)<=V_Ilim
V_cv=Vocp_function(SOCA(1));
ga1=[1 0 1 0];
ga2=[1 0 0 1];
ga3=[1 0 1 0];
gb1=[1 0 1 0];
gb2=[1 0 0 1];
gb3=[1 0 1 0];
gc1=[1 0 1 0];
gc2=[1 0 0 1];
gc3=[1 0 1 0];
elseif SOCB(2)<=V_Ilim || SOCC(2)<=V_Ilim
V_cv=Vocp_function(SOCA(1));
ga1=[1 0 1 0];
ga2=[1 0 1 0];
ga3=[1 0 0 1];
gb1=[1 0 1 0];
gb2=[1 0 1 0];
gb3=[1 0 0 1];
gc1=[1 0 1 0];
gc2=[1 0 1 0];
gc3=[1 0 0 1];
else
V_cv=0;
end
end
end
  2 commentaires
Walter Roberson
Walter Roberson le 19 Mar 2021
persistent R
R=[];
if isempty(R)==1
R=0;
end
What is the purpose of doing the R=[] followed by isempty(R ) ? Why not just directly do
R = 0;
??
What is the purpose of using persistent when you always overwrite R ?
Federico Lusardi
Federico Lusardi le 19 Mar 2021
Thank you Walter, in fact it is a reduntant (and usless) part of code. it was only a first attempt to be sure that in all condition V_cv is assigned and defined, to avoid the error.

Connectez-vous pour commenter.

Réponse acceptée

Gargi Patil
Gargi Patil le 24 Mar 2021
In the given function, an error is being thrown due to the output variable ‘V_cv. The error message ‘Output argument is not assigned on some execution paths’ typically occurs if there is an if-else pathway for which the output variable is not assigned a value. To fix this, a catch-all else condition should be used that assigns a default value to the variable V_cv when none of the ‘if’ conditions are meant.
You can refer to the following question link which also explains this error:
  1 commentaire
Federico Lusardi
Federico Lusardi le 24 Mar 2021
Thank you Gargy, in fact the problem was that for path If R==2 and R==3 no V_cv was define. By adding and checking else condition I solve the problem.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Event Functions dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by