Coder, randsample: Variable 'edges' is not fully defined on some execution paths.
显示 更早的评论
I'm trying to compile a Matlab code with the coder that calls randsample(n,k,true,w) for integers n and k and a weight-vector w. I get the error message, "Variable 'edges' is not fully defined on some execution paths." which seems to be a problem within the randsample function. Any ideas what to do without touching randsample.m itself? Thanks
采纳的回答
更多回答(1 个)
Joel Fernandez
2018-8-6
编辑:Stephen23
2018-8-6
Hi everyone Can someone help me ? My code error is: "Variable 'sa' is not fully defined on some execution paths" So I'm using this code to SVPWM
function sf =aaa(u)
ts=0.0002;vdc=1;peak_phase_max= vdc/sqrt(3);
x=u(2); y=u(3);
mag=(u(1)/peak_phase_max) * ts;
%sector I
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
sf=[sa, sb, sc];
Thanks
1 个评论
@Joel Fernandez: your code is badly aligned. Badly aligned code is one way that beginners hide bugs in their code. You should align your code using the default MATLAB editor settings. You can align the code: select all code, then click ctrl+i. It will give this:
function sf = aaa(u)
ts = 0.0002; vdc = 1; peak_phase_max = vdc / sqrt(3);
x = u(2); y = u(3);
mag = (u(1) / peak_phase_max) * ts;
%sector I
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
sf = [sa, sb, sc];
This makes it clear that if x<0 or x>pi/3 or any of the y>t1 then sa, sb and sc will not be defined, thus the error message.
Note that using lots of superfluous whitepsace in this vector has made it unclear what it should contain:
[t0 / 4 ta / 2 tb / 2 t0 / 2 tb / 2 ta / 2 t0 / 4];
It is clearer to use commas instead of whitespace to separate the array elements, and to not use whitespace around operators, e.g.:
[t0/4, ta/2, tb/2, t0/2, tb/2, ta/2, t0/4];
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB Coder 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!