如何在matlab中避免重复搜索对象?
1、figure
运行这个函数,你可以得到图片。

2、ax = axes;

3、for ix=1:500
for循环,ix为起点为1,终点为500,步进为1。
4、line(rand(1,5),rand(1,5),'Tag',num2str(ix),'Parent',ax);

5、end
%循环的结束语。

6、drawnow;
7、for ix=1:500
for循环,ix为起点为1,终点为500,步进为1。
8、h = findobj(ax,'Tag',num2str(ix));
9、set(h,'Color',rand(1,3));
%设置h的颜色。
10、end
drawnow;

11、更好的方法是将数组中的句柄和索引保存到第二个循环中的数组中。
12、figure
ax = axes;
h = gobjects(1,500);
for ix = 1:500
h(ix) = line(rand(1,5),rand(1,5),'Tag',num2str(ix),'Parent',ax);
end
drawnow;
% Index into handle array
for ix=1:500
set(h(ix),'Color',rand(1,3));
end
drawnow

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:119
阅读量:172
阅读量:148
阅读量:187
阅读量:137