Coder, randsample: Variable 'edges' is not fully defined on some execution paths.
Mostrar comentarios más antiguos
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
Michael Hartmann
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.
Michael Hartmann
el 31 de Jul. de 2018
Respuesta aceptada
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
@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];
Categorías
Más información sobre MATLAB Coder en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!