Matlab:使用矩形函数获得的错误
Matlab: Error obtained with rectangle function
我正在使用 MATLAB 并想使用 rectangle
函数来绘制矩形。我希望用户输入每个角的坐标。我写了以下内容:
xR1 = input('x coordinate of the first rectangle corner?');
yR1 = input('y coordinate of the first rectangle corner?');
xR2 = input('x coordinate of the second rectangle corner?');
yR2 = input('y coordinate of the second rectangle corner?');
xR3 = input('x coordinate of the third rectangle corner?');
yR3 = input('y coordinate of the third rectangle corner?');
xR4 = input('x coordinate of the fourth rectangle corner?');
yR4 = input('y coordinate of the fourth rectangle corner?');
XRcoordinates = [xR1 xR2 xR3 xR4]
YRcoordinates = [yR1 yR2 yR3 yR4]
width = max(XRcoordinates) - min(XRcoordinates)
height = max(YRcoordinates) - min(YRcoordinates)
rectangle('Position', min(XRcoordinates), min(YRcoordinates),width,height)
axis([0 max(XRcoordinates) 0 max(YRcoordinates) ])
当我运行它时我输入以下内容
xR1 = 2
yR1 = 3
xR2 = 2
yR2 = 5
xR3 = 4
yR3 = 5
xR4 = 4
yR4 = 3
但我收到以下错误消息:
Error using rectangle
Can't specify convenience arg for this object
Error in script1
(line 37)
rectangle('Position', min(XRcoordinates),min(YRcoordinates),width,height)
第一条错误消息是什么意思?
怎么了?
您没有正确调用 rectangle
。如果您使用 Position
标志,则第二个参数需要一个 four 元素向量。您正在尝试使用五个参数调用 rectangle
。然而,你应该格式化这个向量的方式与 Position
标志之后的输入参数完全对应,所以你真正需要做的就是将它们封装到一个向量中。
此外,您可能想将矩形的颜色更改为其他颜色,因为默认颜色为黑色。尝试将其更改为红色之类的东西。我们可以在 Position
标志后附加额外的参数。
因此,这样做:
rectangle('Position', [min(XRcoordinates), min(YRcoordinates),width,height], 'EdgeColor', 'red');
我正在使用 MATLAB 并想使用 rectangle
函数来绘制矩形。我希望用户输入每个角的坐标。我写了以下内容:
xR1 = input('x coordinate of the first rectangle corner?');
yR1 = input('y coordinate of the first rectangle corner?');
xR2 = input('x coordinate of the second rectangle corner?');
yR2 = input('y coordinate of the second rectangle corner?');
xR3 = input('x coordinate of the third rectangle corner?');
yR3 = input('y coordinate of the third rectangle corner?');
xR4 = input('x coordinate of the fourth rectangle corner?');
yR4 = input('y coordinate of the fourth rectangle corner?');
XRcoordinates = [xR1 xR2 xR3 xR4]
YRcoordinates = [yR1 yR2 yR3 yR4]
width = max(XRcoordinates) - min(XRcoordinates)
height = max(YRcoordinates) - min(YRcoordinates)
rectangle('Position', min(XRcoordinates), min(YRcoordinates),width,height)
axis([0 max(XRcoordinates) 0 max(YRcoordinates) ])
当我运行它时我输入以下内容
xR1 = 2
yR1 = 3
xR2 = 2
yR2 = 5
xR3 = 4
yR3 = 5
xR4 = 4
yR4 = 3
但我收到以下错误消息:
Error using
rectangle
Can't specify convenience arg for this object
Error in
script1
(line 37)
rectangle('Position', min(XRcoordinates),min(YRcoordinates),width,height)
第一条错误消息是什么意思? 怎么了?
您没有正确调用 rectangle
。如果您使用 Position
标志,则第二个参数需要一个 four 元素向量。您正在尝试使用五个参数调用 rectangle
。然而,你应该格式化这个向量的方式与 Position
标志之后的输入参数完全对应,所以你真正需要做的就是将它们封装到一个向量中。
此外,您可能想将矩形的颜色更改为其他颜色,因为默认颜色为黑色。尝试将其更改为红色之类的东西。我们可以在 Position
标志后附加额外的参数。
因此,这样做:
rectangle('Position', [min(XRcoordinates), min(YRcoordinates),width,height], 'EdgeColor', 'red');