line function gives Error: Expression or statement is incorrect--possibly unbalanced (, {, or [

line function gives Error: Expression or statement is incorrect--possibly unbalanced (, {, or [

%// input points of an object
Point=[0 0 0;
4.25 0 0;
4.25 0 0.7;
3.1 0 1;
2.2 0 1.5;
0.5 0 1.5;
0 0 1;
0 1.70 0;
4.25 1.70 0;
4.25 1.70 0.7;
3.1 1.7 1;
2.2 1.7 1.5;
0.5 1.7 1.5;
0 1.7 1];

%// Line index of the object
LineIndex= [1 2
2 3
3 4
4 5
5 6
6 7
7 1
2 9
9 10
10 11
11 12
12 13
13 14
14 8
8 9
3 10
4 11
5 12
6 13
7 14
1 8];

%// Patch index of the object
PatchIndex{1} = [1 2 3 4 5 6 7];
PatchIndex{2} = [8 9 10 11 12 13 14];
PatchIndex{3} = [2 9 10 3];
PatchIndex{4} = [3 10 11 4];
PatchIndex{5} = [4 11 12 5];
PatchIndex{6} = [5 12 13 6];
PatchIndex{7} = [6 13 14 7];
PatchIndex{8} = [7 14 8 1];
PatchIndex{9} = [1 8 9 2];

%// create a wireframe model
figure;
hold on;
for k1=1:size(LineIndex,1)
    line([Point(LineIndex(k1,1), 1), Point(LineIndex(k1,2), 1)],
         [Point(LineIndex(k1,1), 2), Point(LineIndex(k1,2), 2)],
         [Point(LineIndex(k1,1), 3), Point(LineIndex(k1,2), 3)]);
end
axis equal;
axis([-0.5, 5, -0.5, 2, -0.5 2]);
view(-5, 32);

我已经看了这段代码 2 个小时了,我不明白为什么 line 函数不接受参数并显示线框。

我收到的错误是:

Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.

该错误是因为您的语句跨越多行,并且 MATLAB 要求您在继续到下一行的任何行的末尾添加 ellipsis

尝试

line([Point(LineIndex(k1,1), 1), Point(LineIndex(k1,2), 1)], ...
     [Point(LineIndex(k1,1), 2), Point(LineIndex(k1,2), 2)], ...
     [Point(LineIndex(k1,1), 3), Point(LineIndex(k1,2), 3)]);