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
2 个评论
VBBV
2022-6-2
Is this function saved in a separate m file ? Or inside an m file with a different name ?
采纳的回答
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
2 个评论
Matt J
2022-6-2
You are quite welcome, but please Accept-click the answer to indicate that it resolved your question.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!