Why is plot3 slow when I use it in a loop?
3 次查看(过去 30 天)
显示 更早的评论
I create plot3 in gui axes, if the number of elements that the many depictions of the process is very slow, if you can provide solutions
for i=1:length(AX(:,1))
plot3(AX(i,:),AZ(i,:),AY(i,:),'-c','LineWidth',0.25);
hold on
plot3(AXD(i,:),AZD(i,:),AYD(i,:),'-g','LineWidth',0.5);
end
0 个评论
回答(2 个)
Andrew Newell
2011-6-8
You could try using line instead of plot3. You'll have to make sure all your options come in pairs, e.g.,
line(AX(i,:),AZ(i,:),AY(i,:),'LineStyle','-','Color','c','LineWidth',0.25);
EDIT: With the data you provided, I tried these commands and it worked fine.
for i=1:size(AX,2)
line(AX(i,:),AZ(i,:),AY(i,:),'LineStyle','-', ...
'Color','c','Marker','.','LineWidth',1)
line(AXD(i,:),AZD(i,:),AYD(i,:),'LineStyle','-', ...
'Color','g','Marker','.','LineWidth',1)
end
On my machine this is 4 times faster than using the code you provided. Note that when you use line the image is saved by default, so you don't need hold on.
Walter Roberson
2011-6-8
You only need to execute the "hold on" once; after that it is set and becomes a waste of time.
At some point, you are going to exceed the amount of memory that your graphics card has easily available; things will slow down then.
You could experiment with switching renderers.
6 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!