MatLab does not like my function. It says I need an 'end', but I have one.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kerry Paparusi
el 2 de Jun. de 2022
Comentada: Matt J
el 2 de Jun. de 2022
function drawbox(v0,v,width,color)
box=zeros(2,6);
tmp=hypot(v(3)-v0(3),v(1)-v0(1));
if tmp > 1e-8
p=[v(3)-v0(3),0,-(v(1)-v0(1))]/tmp;
box(:,1)=[v0(3),v0(1)];
box(:,2)=[v0(3)+p(3)*width,v0(1)+p(1)*width];
box(:,3)=[v(3)+p(3)*width,v(1)+p(1)*width];
box(:,4)=[v(3)-p(3)*width,v(1)-p(1)*width];
box(:,5)=[v0(3)-p(3)*width,v0(1)-p(1)*width];
box(:,6)=[v0(3),v0(1)];
end
2 comentarios
VBBV
el 2 de Jun. de 2022
Is this function saved in a separate m file ? Or inside an m file with a different name ?
Respuesta aceptada
Matt J
el 2 de Jun. de 2022
Editada: Matt J
el 2 de Jun. de 2022
Your if statement is closed by an end, but the function statement needs one as well, in certain circumstances.
function drawbox(v0,v,width,color)
box=zeros(2,6);
tmp=hypot(v(3)-v0(3),v(1)-v0(1));
if tmp > 1e-8
p=[v(3)-v0(3),0,-(v(1)-v0(1))]/tmp;
box(:,1)=[v0(3),v0(1)];
box(:,2)=[v0(3)+p(3)*width,v0(1)+p(1)*width];
box(:,3)=[v(3)+p(3)*width,v(1)+p(1)*width];
box(:,4)=[v(3)-p(3)*width,v(1)-p(1)*width];
box(:,5)=[v0(3)-p(3)*width,v0(1)-p(1)*width];
box(:,6)=[v0(3),v0(1)];
end
end
2 comentarios
Matt J
el 2 de Jun. de 2022
You are quite welcome, but please Accept-click the answer to indicate that it resolved your question.
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Objects 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!