Tak
Tak

Reputation: 3616

Figure in function not updated on runtime Matlab

I have a function E which has a for loop, in this loop I open an image to draw on using imshow(im,'Colormap',jet) then another function M is called, in fn M there is another loop where a I'm using the line matlab function to draw points in on the image im. The problem is that if I run fn M without being called from fn E "which means only one iteration of the E function, the figure appears very quickly and in real time. But if I called it from fn E the image don't show up until I quit because the loop has large number of iterations, where only a part of the image is drawn. I don't know how can I make the image shows on real-time showing the updates of every iteration? so if anyone could advise. The code of the two functions is very big that's why I couldn't post it.

This is a sample of my code:

%function E
function E
for..
M(D)
end

%function M
function M(D)
imshow(D,'Colormap',jet)
for..
for..
line([i],[j],'Marker','p','color','g','linewidth',1,'MarkerSize',7)
end
end

Upvotes: 0

Views: 637

Answers (2)

horchler
horchler

Reputation: 18494

Don't use pause, use drawnow, which explicitly flushes the graphics queue. If you like, you can use drawnow('expose'), which may be faster, but things like window resizing in fast loops might not work.

Upvotes: 2

ramino
ramino

Reputation: 498

you can use a small amount of time paused in the for loop to give the time for rendering. e.g use pause(.1) in the loop, after calling function M.

Upvotes: 0

Related Questions