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

2 ビュー (過去 30 日間)
Hossein Rouhabadi
Hossein Rouhabadi 2020 年 1 月 4 日
コメント済み: Hossein Rouhabadi 2020 年 1 月 4 日
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