Variable 'Vec1' is not fully defined on some execution paths.

조회 수: 2 (최근 30일)
I am trying to insert each element of two 1x6 matrices into their respective equations within one FOR Loop. However, I get the following error:
Variable 'Vec1' is not fully defined on some execution paths.
Function 'MVDMPC of MSC' (#127.4865.4869), line 181, column 12: "Vec1"
vnz1=[v1 v2 v3 v4 v5 v6];
vnz2=[v2 v3 v4 v5 v6 v1]; % vnz1(i) and vnz2(i) are complex numbers.
for i = 1:6
v_opt1_k1 = vnz1(i);
v_opt2_k1 = vnz2(i);
ia_1_k2 = ia_0_est_k2 - (C2 * real(v_opt1_k1));
ib_1_k2 = ib_0_est_k2 - (C2 * imag(v_opt1_k1));
I_1_k2 = sqrt(((ia_1_k2)^2)+((ib_1_k2)^2));
ia_2_k2 = ia_0_est_k2 - (C2 * real(v_opt2_k1));
ib_2_k2 = ib_0_est_k2 - (C2 * imag(v_opt2_k1));
I_2_k2 = sqrt(((ia_2_k2)^2)+((ib_2_k2)^2));
g1 = sqrt(((ia_1_k2 - ia_ref_k)^2)+((ib_1_k2 - ib_ref_k)^2));
g2 = sqrt(((ia_2_k2 - ia_ref_k)^2)+((ib_2_k2 - ib_ref_k)^2));
if I_1_k2 > i_max || I_2_k2 > i_max
sat = inf;
else
sat = 0;
end
g = g1 + g2 + sat;
if g < g_opt
g_opt = g;
x_opt = i;
n_sec = i;
Vec1 = v_opt1_k1;
Vec2 = v_opt2_k1;
%else
% g_opt = g_opt
%elseif g >= g_opt
% g_opt = g_opt
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Store the present value of x_opt
x_old = x_opt;
VolVec1 = Vec1;
VolVev2 = Vec2;
What I have tried so far:
  • Modification of the the IF Loop of the cost function g (with else and elseif as shown in the code with % sign)............. didn't work.
  • Deleting the whole IF Loop of the system constraint "i_max".......... didn't work
  • Reallocating the outputs inside and outside the FOR Loop........ didn't work
I do not know to what and where this error could be related.
Any sort of help is appreciated.

채택된 답변

Walter Roberson
Walter Roberson 2020년 1월 4일
Pre-allocate Vec1 and Vec2 before the for loop, by assigning inf to them.
MATLAB cannot prove that g < g_opt will be definitely be true on some iteration, so it thinks that it is possible that you will go through all of the loops without having assigned to Vec1 .
  댓글 수: 1
Hossein Rouhabadi
Hossein Rouhabadi 2020년 1월 4일
Nice! That works.... I had to put n_sec to inf as well. Thanks a lot Walter.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by