Help with 'Variable 'sa' is undefined on some execution paths'
2 次查看(过去 30 天)
显示 更早的评论
Hi
I have an issue when I am trying to build an SVPWM Inverter model for my final year Uni project.
I have used the following paper as a guide as one of the authors also wrote a book on the subject, which I have attached.
I have adapted the code from this paper and I am getting an undefined variable error for 'sa' when looking at the diagnostic report the error does not occur for variables 'sb' or 'sc'.
Here is the code:
%Switching Function Matlab Code %Inputs are magnitude (u1), angle (u2) and ramp signal (u3)
function sf = aaa(u) ts = 0.0002; vdc = 1; max_peak_phase = vdc/sqrt(3); x = u(2); y = u(3); mag = (u(1)/max_peak_phase)*ts;
%Sector 1
if (x>=0)&&(x<(pi/3)); ta = mag*sin((pi/3)-x); tb = mag*sin(x); t0 = (ts-ta-tb);
t1 = [t0/4 ta/2 tb/2 t0/2 tb/2 ta/2 t0/4]; t1 = cumsum(t1); v1 = [0 1 1 1 1 1 0]; v2 = [0 0 1 1 1 0 0]; v3 = [0 0 0 1 0 0 0];
for j = 1:7;
if (y<t1(j))
break
end
end
sa = v1(j);
sb = v2(j);
sc = v3(j);
end
%Sector 2
if (x>=(pi/3))&&(x<(2*pi/3));
adv = x-(pi/3);
ta = mag*sin((pi/3)-adv);
tb = mag*sin(adv);
t0 = (ts-ta-tb);
t1 = [t0/4 ta/2 tb/2 t0/2 tb/2 ta/2 t0/4]; t1 = cumsum(t1); v1 = [0 0 1 1 1 0 0]; v2 = [0 1 1 1 1 1 0]; v3 = [0 0 0 1 0 0 0];
for j = 1:7;
if (y<t1(j))
break
end
end
sa = v1(j);
sb = v2(j);
sc = v3(j);
end
%Sector 3
if (x>=(2*pi/3))&&(x<pi);
adv = x-(2*pi/3);
ta = mag*sin((pi/3)-adv);
tb = mag*sin(adv);
t0 = (ts-ta-tb);
t1 = [t0/4 ta/2 tb/2 t0/2 tb/2 ta/2 t0/4]; t1 = cumsum(t1); v1 = [0 0 0 1 0 0 0]; v2 = [0 1 1 1 1 1 0]; v3 = [0 0 1 1 1 0 0];
for j = 1:7;
if (y<t1(j))
break
end
end
sa = v1(j);
sb = v2(j);
sc = v3(j);
end
%Sector 4
if (x>=-pi)&&(x<-(2*pi/3));
adv = x+pi;
ta = mag*sin(adv);
tb = mag*sin((pi/3)-adv);
t0 = (ts-ta-tb);
t1 = [t0/4 ta/2 tb/2 t0/2 tb/2 ta/2 t0/4]; t1 = cumsum(t1); v1 = [0 0 0 1 0 0 0]; v2 = [0 0 1 1 1 0 0]; v3 = [0 1 1 1 1 1 0];
for j = 1:7;
if (y<t1(j))
break
end
end
sa = v1(j);
sb = v2(j);
sc = v3(j);
end
%Sector 5
if (x>=-(2*pi/3))&&(x<-(pi/3));
adv = x+(2*pi/3);
ta = mag*sin(adv);
tb = mag*sin((pi/3)-adv);
t0 = (ts-ta-tb);
t1 = [t0/4 ta/2 tb/2 t0/2 tb/2 ta/2 t0/4]; t1 = cumsum(t1); v1 = [0 0 1 1 1 0 0]; v2 = [0 0 0 1 0 0 0]; v3 = [0 1 1 1 1 1 0];
for j = 1:7;
if (y<t1(j))
break
end
end
sa = v1(j);
sb = v2(j);
sc = v3(j);
end
%Sector 6
if (x>=-(pi/3))&&(x<0);
adv = x+(pi/3);
ta = mag*sin(adv);
tb = mag*sin((pi/3)-adv);
t0 = (ts-ta-tb);
t1 = [t0/4 ta/2 tb/2 t0/2 tb/2 ta/2 t0/4]; t1 = cumsum(t1); v1 = [0 1 1 1 1 1 0]; v2 = [0 0 0 1 0 0 0]; v3 = [0 0 1 1 1 0 0];
for j = 1:7;
if (y<t1(j))
break
end
end
sa = v1(j);
sb = v2(j);
sc = v3(j);
end
sf = [sa, sb, sc];
end
I apologise if this sounds really basic and if I have not asked correctly, I am a very basic user of Matlab and programming altogether and I am still trying to get an understanding.
Thanks
Jack
0 个评论
回答(1 个)
Niels
2015-2-3
You have 6 if-statements. Could it be that your x falls out of the ranges you've specified?
Just for clarity - your total range varies from -pi to +pi, but it does not include +pi itself. Is that the way it should be?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Manual Performance Optimization 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!