Variable 'Vec1' is not fully defined on some execution paths.
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hossein Rouhabadi
am 4 Jan. 2020
Kommentiert: Hossein Rouhabadi
am 4 Jan. 2020
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.
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.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 4 Jan. 2020
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 .
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Preview and Device Configuration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!