问题描述
我试图在循环中显示一个带有暂停的变化的矩形,并且它忽略了延迟(实际上应该是默认值).
I'm trying to display a changing rectangle in a loop, with pause, and it ignores hold off (which actually suppose to be default).
这是简化版的代码:
clc; close all; clear all;
rect = [10 10 20 30];
figure
axis([0 200 0 50]);
for i = 1 : 15
rect(1) = rect(1) + i;
rectangle('Position', rect, 'edgeColor', [1 0 0]);
hold off;
pause(0.2);
end
是故意的吗?我想念什么吗?除了在每次迭代后将其绘制成白色外,我还能做些什么使前面的矩形消失?
Is it on purpose?Am I missing something?What can I do to make the previous rectangles disappear, aside from ploting it in white after each iteration?
谢谢..
解决了非常简化的版本,但是如果我还想在同一图形上绘制其他内容,则其他绘制将忽略延迟.在这种情况下我该怎么办?
The very simplified version was solved, but if I want to also plot another thing on the same figure, the other plot ignores hold off.What should I do in this case?
再次感谢.
clc; close all; clear all;
rect = [10 10 20 30];
figure
axis([0 200 0 50]);
h1 = [];
for i = 1 : 15
rect(1) = rect(1) + i;
delete(h1);
h1 = rectangle('Position', rect, 'edgeColor', [1 0 0]);
hold on
plot (5 + 5 * i, 5, '*g');
hold off
pause(0.2);
end
推荐答案
更新:Matlab R2014b及更高版本
使用 手柄图形引擎的更新 在Matlab R2014b中,文档中的表示法发生了一些变化.没有与众不同的网站核心图形对象和绘图对象,但 此处 ,您会看到两种对象现在称为绘图功能对象和原始对象
Update: Matlab R2014b and later
With the update of the handle graphics engine in Matlab R2014b the notation in the documentation changed a little. There are no distinctive sites forCore Graphics Objects and Plot Objects anymore, but here you can see that the two kind of objects are now called Plotting Function Objects and Primitive Objects.
原因是 绘制对象 ,目的是使用Core Graphics Objects来显示数据.
The reason is, that there is a difference between Core Graphics Objects made for drawing and its subgroup Plot Objects with the purpose of displaying data, using Core Graphics Objects to do that.
核心图形对象
-
线,文本和多边形壳(修补对象)
Line, text, and polygon shells (patch objects)
像表面这样的特殊对象,由矩形的顶点网格组成
Specialized objects like surfaces, which are composed of a rectangular grid of vertices
图片
浅色对象,这些对象不可见,但会影响某些对象的着色方式
Light objects, which are not visible but affect the way some objects are colored
绘制对象
一个典型的例子是命令line
和plot
-基本上是相同的.但是他们属于不同的群体.如果要绘制数据,他将使用plot
任务已完成.如果要使用线来绘制"某些东西会更容易,那么您将不必总是全部hold
.
A characteristic example would be the commands line
and plot
- which are basically the same. But they belong to different groups. If one wants to plot data, he uses plot
, task done. If one wants to "draw" something with lines its easier you wouldn't always need to hold
everything.
所以回答您的问题:是的,这是有目的的.
为了解决您的问题,我将使用plot
编写一个新的矩形函数:
And to solve your problem, I would write a new rectangle function using plot
:
function h = plotRectangle(posX, posY, width, height)
x = [posX posX+width posX+width posX posX];
y = [posY posY posY+height posY+height posY];
h = plot(x,y);
end
分别:
function h = plotRectangle(PosVector)
X = PosVector;
x = [X(1) X(1)+X(3) X(1)+X(3) X(1) X(1)];
y = [X(2) X(2) X(2)+X(4) X(2)+X(4) X(2)];
h = plot(x,y);
end
您现在可以将其与代码一起使用了:
The latter you can now use with your code:
rect = [10 10 20 30];
figure
axis([0 200 0 50]);
for i = 1 : 15
rect(1) = rect(1) + i;
plotRectangle(rect);
hold off;
pause(0.2);
end
这篇关于为什么诸如“矩形"和“线"之类的绘图命令会忽略“推迟"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!