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

3 ビュー (過去 30 日間)
Federico Lusardi
Federico Lusardi 2021 年 3 月 19 日
コメント済み: Federico Lusardi 2021 年 3 月 24 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 3 月 19 日
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 2021 年 3 月 19 日
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.

サインインしてコメントする。

採用された回答

Gargi Patil
Gargi Patil 2021 年 3 月 24 日
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 件のコメント
Federico Lusardi
Federico Lusardi 2021 年 3 月 24 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by