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

4 vues (au cours des 30 derniers jours)
Abdulwasiu Yusuf
Abdulwasiu Yusuf le 28 Jan 2020
Hi.
I'm trying to implement Space Vector PWM. I created a function to calculate my time and as well as the switching time for the inverter.
I however get "Output argument 'S1' is not assigned on some execution paths." as the error. I have looked through and try out diffrent approach, nothing seems to work.
Please i need help to resolve this persistent error.
I have also attached a copy of the file. (downgarded to 2013version)
This is the complete Matlab function.
% I have 3 input into the function block%
% The Magnitude, the Angle (radian) and the Sequence block in that order%
% The output goes to my inverter IGBT's swith input%
function [S1,S3,S5,S4,S6,S2] = fcn(u)
b = sqrt(3);
Vdc = 400;
Fs = 5000;
Ts = 1 / Fs;
m = pi/3;
Alpha = u(2);
A = b * Ts * u(1) / (Vdc);
if (Alpha > 0) && (Alpha <= m)
K =1; %for sector 1%
Ta = A * sin((K * m) - Alpha);
Tb = A * sin(Alpha);
To = Ts - Ta - Tb;
a = To/4;
b = Ta/2;
c = Tb/2;
d = To/2;
T = [a b c d c b a];
T_T = cumsum(T);
SA = [0 1 1 1 1 1 0];
SB = [0 0 1 1 1 0 0];
SC = [0 0 0 1 0 0 0];
for e = 1:7
if(u(3) < T_T)
break
end
end
S1 = SA(e);
S3 = SB(e);
S5 = SC(e);
S4 = 1-SA(e);
S6 = 1-SB(e);
S2 = 1-SC(e);
end

Réponse acceptée

Image Analyst
Image Analyst le 29 Jan 2020
Have the first lines right after the function line be assignments for the S's.
S1 = nan; % or zero or -inf or whatever you want.
S3 = nan;
S5 = nan;
S4 = nan;
S6 = nan;
S2 = nan;
That way, not matter what happens (like you don't assign them afterwards for whatever reason, which is what happened), they will at least have a value and that particular error won't happen.
  2 commentaires
Abdulwasiu Yusuf
Abdulwasiu Yusuf le 29 Jan 2020
Thanks.
I tried this approach, the error was gone, but the output was'nt as expected. it seems this line in the code
S1 = SA(e);
S3 = SB(e);
S5 = SC(e);
S4 = 1-SA(e);
S6 = 1-SB(e);
S2 = 1-SC(e);
affects the desired final output of [S1:S6] when you give it nan or -inf initialization.
Abdulwasiu Yusuf
Abdulwasiu Yusuf le 29 Jan 2020
Hi , Thanks so much , it finally worked
I declared it as
S1 = nan;
S3 = nan;
S5 = nan;
S4 = nan;
S6 = nan;
S2 = nan;
the other error I didn't catch was my for loop.
for e = 1:7
if(u(3) < T_T)
break
end
end
it was missing the the index checker (e). in the "if statement
I thus resolved it by changing the code to
for e = 1:7
if(u(3) < T_T(e))
break
end
end
'"
Everything now works great. !!!!
Thanks

Connectez-vous pour commenter.

Plus de réponses (2)

Walter Roberson
Walter Roberson le 28 Jan 2020
When
if (Alpha > 0) && (Alpha <= m)
is false, then you do not assign any value to S1.
There might be other constraints in the model that force u(2) to always be in the range eps(realmin) to pi/3 so it might be a problem more in theory than in practice, but the optimizer doesn't know anything about that.
  1 commentaire
Abdulwasiu Yusuf
Abdulwasiu Yusuf le 29 Jan 2020
Yes, u(2) is a repeated sequence tied in the range of [0 pi/3 2pi/3 0 -2pi/3 -pi/3 0] in that order, and it corresponds to a sector in the Space Vector plane.
i.e,
0 to pi/3 Sector 1
pi/3 to 2pi/3 Sector 2
2pi/3 to 0 Sector 3
0 to -2pi/3 Sector 4
-2pi/3 to -pi/3 Sector 5
-pi/3 to 0 Sector 6
And the function block will check u(2) state and generate the time interval for each sector to occur.

Connectez-vous pour commenter.


Abdulwasiu Yusuf
Abdulwasiu Yusuf le 29 Jan 2020
Resolved and now working!!!
% I have 3 input into the function block%
% The Magnitude, the Angle (radian) and the Sequence block in that order%
% The output goes to my inverter IGBT's swith input%
function [S1,S3,S5,S4,S6,S2] = fcn(u)
S1 = nan;
S3 = nan;
S5 = nan;
S4 = nan;
S6 = nan;
S2 = nan;
b = sqrt(3);
Vdc = 400;
Fs = 5000;
Ts = 1 / Fs;
m = pi/3;
Alpha = u(2);
A = b * Ts * u(1) / (Vdc);
if (Alpha >= 0) && (Alpha < m)
K =1; %for sector 1%
Ta = A * sin((K * m) - Alpha);
Tb = A * sin(Alpha);
To = Ts - Ta - Tb;
a = To/4;
b = Ta/2;
c = Tb/2;
d = To/2;
T = [a b c d c b a];
T_T = cumsum(T);
SA = [0 1 1 1 1 1 0];
SB = [0 0 1 1 1 0 0];
SC = [0 0 0 1 0 0 0];
for e = 1:7
if(u(3) < T_T (e))
break
end
end
S1 = SA(e);
S3 = SB(e);
S5 = SC(e);
S4 = 1-SA(e);
S6 = 1-SB(e);
S2 = 1-SC(e);
end
end

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by