I am unable to understand the error, Output argument "k" (and maybe others) not assigned during call to "trail3>A".
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
sai sathvik
el 6 de Mayo de 2021
Comentada: sai sathvik
el 9 de Mayo de 2021
function k = A(ia,tete)
if 0<tete && tete< pi/3
k = ia;
elseif pi/3 <tete && tete<2*pi/3
k = ia;
elseif 2*pi/3<tete && tete<pi
k = 0;
elseif pi<tete && tete<4*pi/3
k = -ia;
elseif 4*pi/3<tete && tete<5*pi/3
k = -ia;
elseif 5*pi/3<tete && tete<2*pi
k =0;
end
end
0 comentarios
Respuesta aceptada
Image Analyst
el 7 de Mayo de 2021
None of your if blocks ever gets entered and so k is never defined, yet you try to return it -- hence the error. Assign it to whatever value you want it to have if no criteria is met, like inf, [], 0, or -1 or whatever. I always initialize my variables to something right in the first lines in the function so that in case something goes wrong, at least you won't get the error like you got. Fixed code:
function k = A(ia,tete)
% Initialize k
k = 0;
if 0 < tete && tete < pi/3
k = ia;
elseif pi/3 < tete && tete < 2*pi/3
k = ia;
elseif 2*pi/3 < tete && tete < pi
k = 0;
elseif pi < tete && tete < 4*pi/3
k = -ia;
elseif 4*pi/3 < tete && tete < 5*pi/3
k = -ia;
elseif 5*pi/3 < tete && tete < 2*pi
k =0;
else
% You get here if none of the other criteria were met.
k = 0;
end
end
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!