MATLAB: Plot in a videopreview

plot videopreview

Hi, I'm using a videopreview and trying to plot a line every time the video preview is updated, using the UpdatePreviewWindowFcn.
The problem is that when I plot, appears a new figure, instead of plotting on the videopreview.
function update_preview_display(obj,event,hImage)
image = event.Data;
% Display the current image frame.
set(hImage, 'CData', image);
t = 1:1:50;
g = 1:1:50;
plot(t,g,'g');
drawnow
What am i doing wrong?

Best Answer

plot(t, g, 'g', 'Parent', ancestor(hImage, 'axes'))