Why is plot3 slow when I use it in a loop?
Mostrar comentarios más antiguos
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
Respuestas (2)
Andrew Newell
el 8 de Jun. de 2011
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.
11 comentarios
pink
el 8 de Jun. de 2011
Andrew Newell
el 8 de Jun. de 2011
line(AX(i,:),AZ(i,:),AY(i,:),'LineStyle','-','Color','g','Marker','.','LineWidth',1)
pink
el 8 de Jun. de 2011
Andrew Newell
el 9 de Jun. de 2011
Are you saying that this error only occurs when you use line instead of plot3? Are you changing anything else besides the plot commands?
Walter Roberson
el 9 de Jun. de 2011
size(AX)
size(AZ)
size(AY)
size(AXD)
size(AZD)
size(AYD)
pink
el 9 de Jun. de 2011
pink
el 9 de Jun. de 2011
Andrew Newell
el 9 de Jun. de 2011
See my revised answer.
pink
el 9 de Jun. de 2011
Andrew Newell
el 9 de Jun. de 2011
What do you mean?
pink
el 9 de Jun. de 2011
Walter Roberson
el 8 de Jun. de 2011
0 votos
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 comentarios
pink
el 8 de Jun. de 2011
Walter Roberson
el 8 de Jun. de 2011
set(gcf,'Renderer','zbuffer')
pink
el 8 de Jun. de 2011
Walter Roberson
el 9 de Jun. de 2011
Yes, that could help:
axh = gca;
plot3(axh, AX(1,:),AZ(1,:),AY(1,:),'-c','LineWidth',0.25);
hold(axh,'on')
plot3(axh,AXD(1,:),AZD(1,:),AYD(1,:),'-g','LineWidth',0.5);
for i = 2:length(AX,2)
plot3(axh,AX(i,:),AZ(i,:),AY(i,:),'-c','LineWidth',0.25);
plot3(axh,AXD(i,:),AZD(i,:),AYD(i,:),'-g','LineWidth',0.5);
end
Walter Roberson
el 9 de Jun. de 2011
Should be size(AX,1) instead of length(AX,2)
pink
el 9 de Jun. de 2011
Categorías
Más información sobre Graphics Performance en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!