How to show an updating image generated by "drawnow" in GUI axes1

Hi All, I would like to show an updating image generated by "drawnow" in GUI axes1. This is my code:
function Start_Callback(hObject, eventdata, handles)
set(handles.Start,'string','Running','enable','off');
QuasiBrownianMotion_Co_TimeControl_forGUI;
axes(handles.axes1);
drawnow;
% Update handles structure
guidata(hObject, handles);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
"QuasiBrownianMotion_Co_TimeControl_forGUI" is a function I used to generate images.
The problem right now is whenever I run GUI and hit start button. Matlab always pop out another new image window to show the images instead of showing within axes1. Could anyone help me out? Thanks a lot! Wenlong

7 Comments

Does the function QuasiBrownianMotion_Co_TimeControl_forGUI have the command to draw/display an image? If so, what is that command and how often does it update the image?
You may need to just put the axes(handles.axes1) statement before the call to QuasiBrownianMotion_Co_TimeControl_forGUI in order to get the axes1 updated with the image.
It seems like you will be periodically updating your image via a single call to the brownian motion function. Is that the case?
Hi Geoff, Thanks for your valuable comments first! I am sorry for the missing info! Yes, QuasiBrownianMotion_Co_TimeControl_forGUI also has the command "drawnow".
function QuasiBrownianMotion_Co_TimeControl_forGUI
global state
handles=guidata(gcbo);
colormap gray;
state.h.timer=timer('TimerFcn',@Beat_Co_TimeControl_Circle_forGUI,'ExecutionMode','fixedDelay','Period',.005);
start(state.h.timer);
function Beat_Co_TimeControl_Circle_forGUI(varargin)
global state
handles=guidata(gcbo);
a = tic;
while 1
state.cur_time = toc(a)
if state.cur_time<state.t
k=1;
%change the speed here
while k<state.Nr+state.Nc+1
Bx=unique(get(state.p{k},'xdata'));Bx=Bx([1,end]);
By=unique(get(state.p{k},'ydata'));By=By([1,end]);
if By(1)<=0
state.Vy(k)=-state.Vy(k);
elseif By(2)>=1
state.Vy(k)=-state.Vy(k);
end
if Bx(1)<=0
state.Vx(k)=-state.Vx(k);
elseif Bx(2)>=1
state.Vx(k)=-state.Vx(k);
end
axes(handles.axes1);
set(state.p{k},'xdata',get(state.p{k},'xdata')+state.Vx(k),'ydata',get(state.p{k},'ydata')+state.Vy(k));
% axes(handles.axes1);
drawnow;
k=k+1;
end
Here I put more code to make it clear. I put the axes(handles.axes1) statement before the call to QuasiBrownianMotion_Co_TimeControl_forGUI and also tried to move it ahead of set . However, it still pop out another new image. Thanks again! Wenlong
What is state.p{k}, a handle to something? Is it this set statement this causing the drawing (or re-drawing)?
Hi Geoff, Thanks for your follow up! State p{k} handles the shape of the particles. Set statement set the shape of the particles and the velocity of them. Wenlong
Hi Geoff, do you think it is possible that you can provide me an email address, so I can forward you my .m files? Thanks! Wenlong
Hi Wenlong - You can attach your *.m and *.fig files to any comment you add to your question. Just use the paperclip button to do so.
Sorry! I am a rookie. I will attach the files tomorrow morning since they are in my office computer. Thanks again!

Sign in to comment.

 Accepted Answer

Search your code for "figure" - perhaps you're calling figure which is causing a brand new figure to be created instead of causing the image to appear in an axes control on your existing GUI figure.

2 Comments

Hi Thanks for your answer! The problem is that I am not be able to find a "figure" variable in the code. If there is a "figure" variable, I know we can handle it by using "imshow". If you can provide me an email box, I can send you my .m files. Thanks! Wenlong
I don't have an email address. You can attach m-files and fig files here with the paper clip icon. Or you can step through your code a line at a time to find out where the "pop out another new image window" happens exactly.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!