1

I'm trying to plot a 2d finite element solution and am plotting triangle-by-triangle like so:

for i=1:K
    figure(1)
    fill3(x,y,z,c)
    hold on
end

The problem with this is that when I run the code, it literally draws them all in real time so I can see each triangle being drawn. What I want it to just have the finished figure pop up once it's all done.

My friend has coded the same thing except she's not having this issue at all and we can't find any differences in the code. My computer is very fast so it's not an issue of lag. I'm thinking maybe there's a setting in MATLAB that I'm missing?

Edit: I found the problem. Apparently, putting 'figure(1)' inside the loop makes a huge difference. I timed it with 'tic' and 'toc' and it took 54 seconds with the 'figure(1)' label inside the loop and 2 seconds when it was moved just before the loop. Go figure...

4

1 回答 1

4

When you start the figure, set the visible property to 'off'; when you are done plotting, set the visibility to 'on'.

h = figure('visible','off');
hold on;
for i=1:K    
    fill3(x,y,z,c);
end
hold off;
set(h,'visible','on');

Also, I'm not entirely sure how the event queue works in MATLAB, but I'm fairly sure the fact you have a fast computer is effecting this. You can simulate what's happening with your computer by using drawnow on your friends slower comp within the for-loop.

于 2013-03-30T18:49:10.383 回答