Why is plot3 slow when I use it in a loop?

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

답변 (2개)

Andrew Newell
Andrew Newell 2011년 6월 8일

0 개 추천

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);
See linespec for how to define each property.
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

pink
pink 2011년 6월 8일
sorry andrew,
Error in ==>
main>undeformedbutton_Callback at 653
line
(AX(i,:),AZ(i,:),AY(i,:),'-g.','LineWidth',1);
Andrew Newell
Andrew Newell 2011년 6월 8일
line(AX(i,:),AZ(i,:),AY(i,:),'LineStyle','-','Color','g','Marker','.','LineWidth',1)
pink
pink 2011년 6월 8일
??? Index exceeds matrix dimensions.
Andrew Newell
Andrew Newell 2011년 6월 9일
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
Walter Roberson 2011년 6월 9일
size(AX)
size(AZ)
size(AY)
size(AXD)
size(AZD)
size(AYD)
pink
pink 2011년 6월 9일
AX =[ 0 2.1213;
4.2426 2.1213;
4.2426 2.1213;
0 2.1213]
AY =[ 0 4000;
0 4000;
0 4000;
0 4000]
AZ =[-4.2426 -2.1213;
-4.2426 -2.1213;
0 -2.1213;
0 -2.1213]
AXD =[ 0 2.0900;
4.2426 2.0900;
4.2426 2.0900;
0 2.0900]
AYD =[ 0 3.6818;
0 3.6818;
0 3.6818;
0 3.6818]
AZD =[4.2426 2.1849;
4.2426 2.1849;
0 2.1849;
0 2.1849]
pink
pink 2011년 6월 9일
hi andrew
error occurred, if I change the "plot3"to "line"
Andrew Newell
Andrew Newell 2011년 6월 9일
See my revised answer.
pink
pink 2011년 6월 9일
is work
sorry, but the picture does not fit what I want
Andrew Newell
Andrew Newell 2011년 6월 9일
What do you mean?
pink
pink 2011년 6월 9일
object generated using the "plot3" not the same as using the "line"

댓글을 달려면 로그인하십시오.

Walter Roberson
Walter Roberson 2011년 6월 8일

0 개 추천

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

pink
pink 2011년 6월 8일
hi, Walter
Can you give an example?
Walter Roberson
Walter Roberson 2011년 6월 8일
set(gcf,'Renderer','zbuffer')
pink
pink 2011년 6월 8일
Calling AXES(h) without an output be can slow. Include 'h' in plot fucntion argument
Walter Roberson
Walter Roberson 2011년 6월 9일
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
Walter Roberson 2011년 6월 9일
Should be size(AX,1) instead of length(AX,2)
pink
pink 2011년 6월 9일
AX =[ 0 2.1213;
4.2426 2.1213;
4.2426 2.1213;
0 2.1213]
AY =[ 0 4000;
0 4000;
0 4000;
0 4000]
AZ =[-4.2426 -2.1213;
-4.2426 -2.1213;
0 -2.1213;
0 -2.1213]
AXD =[ 0 2.0900;
4.2426 2.0900;
4.2426 2.0900;
0 2.0900]
AYD =[ 0 3.6818;
0 3.6818;
0 3.6818;
0 3.6818]
AZD =[4.2426 2.1849;
4.2426 2.1849;
0 2.1849;
0 2.1849]

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

태그

질문:

2011년 6월 8일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by