如何在matlab中避免重复搜索对象?

2026-03-04 21:33:50

1、figure

运行这个函数,你可以得到图片。

如何在matlab中避免重复搜索对象?

2、ax = axes;

如何在matlab中避免重复搜索对象?

3、for ix=1:500   

for循环,ix为起点为1,终点为500,步进为1。

4、line(rand(1,5),rand(1,5),'Tag',num2str(ix),'Parent',ax);

如何在matlab中避免重复搜索对象?

5、end

%循环的结束语。

如何在matlab中避免重复搜索对象?

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;

如何在matlab中避免重复搜索对象?

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

如何在matlab中避免重复搜索对象?

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