【问题标题】:Matlab: Error obtained with rectangle functionMatlab:使用矩形函数获得的错误
【发布时间】:2015-03-20 06:55:44
【问题描述】:

我正在使用 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

但我收到以下错误消息:

使用rectangle时出错

无法为此对象指定便利参数

script1 中的错误(第 37 行)

rectangle('Position', min(XRcoordinates),min(YRcoordinates),width,height)

第一条错误信息是什么意思? 怎么了?

【问题讨论】:

  • 我的回答解决了你的问题吗?
  • 是的,非常感谢@rayreng​​span>
  • 没问题!感谢您接受 :) 祝你好运!

标签: image matlab plot rectangles


【解决方案1】:

您没有正确调用rectangle。如果您使用Position 标志,则第二个参数需要一个 元素向量。您正在尝试使用五个参数调用 rectangle。但是,您应该格式化此向量的方式与 Position 标志之后的输入参数完全对应,因此您真正需要做的就是将它们封装到一个向量中。

此外,您可能希望将矩形的颜色更改为其他颜色,因为默认颜色是黑色。尝试将其更改为红色。我们可以在Position 标志之后附加额外的参数。

因此,这样做:

rectangle('Position', [min(XRcoordinates), min(YRcoordinates),width,height], 'EdgeColor', 'red');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多