Output argument 'V_cv' is not assigned on some execution paths.
    7 views (last 30 days)
  
       Show older comments
    
    Federico Lusardi
 on 19 Mar 2021
  
    
    
    
    
    Commented: Federico Lusardi
 on 24 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 Comments
  Walter Roberson
      
      
 on 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 ?
Accepted Answer
  Gargi Patil
    
 on 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: 
More Answers (0)
See Also
Categories
				Find more on Event Functions in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!