Coder, randsample: Variable 'edges' is not fully defined on some execution paths.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Michael Hartmann
el 31 de Jul. de 2018
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
3 comentarios
Stephen23
el 31 de Jul. de 2018
Editada: Stephen23
el 31 de Jul. de 2018
@Michael Hartmann: please upload your code by clicking on the paperclip button.
'"Variable 'edges' is not fully defined on some execution paths." which seems to be a problem within the randsample function'
Interesting. We need to see your code.
Respuesta aceptada
Mike Hosea
el 31 de Jul. de 2018
Editada: Mike Hosea
el 31 de Jul. de 2018
This is a bug in the code generation version of RANDSAMPLE. The compiler is complaining about a situation that it really doesn't need to complain about, as the edges variable is never referenced unless it is first defined as far as I can tell. It's just challenging to infer that from a static analysis.
I'll create an internal bug report for this to get it fixed. It's really just a matter of providing an initialization for edges even when w is empty (e.g. adding
else
edges = zeros('like',w);
before the "end" on line 66 of matlab/toolbox/stats/eml/randsample.m. I mean, that's completely unsupported, and I'm not recommending it. You'd be doing that at your own risk. Really. Who knows what might happen?).
2 comentarios
Mike Hosea
el 2 de Ag. de 2018
Glad to hear it. FYI, 2018b development is currently past the point where we could reasonably slip this in. Just wanted you to know in case you upgrade to 18b and expect to see the fix there.
Más respuestas (1)
Joel Fernandez
el 6 de Ag. de 2018
Editada: Stephen23
el 6 de Ag. de 2018
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 comentario
Stephen23
el 6 de Ag. de 2018
Editada: Stephen23
el 6 de Ag. de 2018
@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];
Ver también
Categorías
Más información sobre MATLAB Coder en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!