Borrar filtros
Borrar filtros

MatLab does not like my function. It says I need an 'end', but I have one.

2 visualizaciones (últimos 30 días)
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
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 ?

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
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
Kerry Paparusi
Kerry Paparusi el 2 de Jun. de 2022
I get it. Thank you. I am very new to this and appreciate your help.
Matt J
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Objects en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by