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

1 次查看(过去 30 天)
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

采纳的回答

Matt J
Matt J 2022-6-2
编辑:Matt J 2022-6-2
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Objects 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by