Clear Filters
Clear Filters

Axes Click in GUI interrupts Figure Plot

5 views (last 30 days)
wise_boss
wise_boss on 21 Jan 2019
Commented: Adam on 23 Jan 2019
I'm basically trying to create a simple GUI to play a video and seek a file, while also plotting an axis figure which shows a vertical line moving with figure frame (figure file attached).
Problem is when I click anywhere on the graph the frames stop updating in the figure, while the rest of the GUI is working. If I then click on the figure area is jumps to the current frame and keeps playing.
This is part of the play button that is responsible for updating the figure window and graph plots.
for frameCount = start_frame:fast_f:max_frames
videoObject = handles.videoObject;
datam = handles.datam;
set(handles.text2,'String',['Frame: ' num2str(frameCount)]);
frame = read(videoObject,frameCount);
imshow(frame);
% Display plot
plot(handles.graph1,datam.t,datam.RFZ_NET,'-b',datam.t,datam.LFZ_NET,'-g');
hold on
tik = frameCount* data_spf * spf_ratio;
line(handles.graph1,[tik,tik],[-50,400],'LineWidth',2,'Color','red')
hold off;
end
Please let me know which parts of code are needed and I'll add them here. problem.PNG
  1 Comment
Adam
Adam on 22 Jan 2019
Edited: Adam on 22 Jan 2019
You should use the imshow syntax specifying a parent ideally. For some reason imshow doesn't appear to do this in the same way as almost every other plotting function so you would need to use
imshow( frame, 'Parent', hAxes )
where hAxes is your axes handle. I'm not convinced this would cause the behaviour you are seeing, but if you are running plotting code in a loop at the same time as clicking places you should definitely be giving an explicit axes handle.
Better still you should keep hold of the image handle the first time you call imshow, then just edit the properties of that image rather than keep replotting. Mostly this should just be the CData property being updated as frame assuming the frame size is not changing constantly. Again though I don't think this will cause what you are seeing.
You also haven't shown all the code though I assume so it's hard to say what else might be interfering.

Sign in to comment.

Answers (2)

Shivaputra Narke
Shivaputra Narke on 21 Jan 2019
check using 'drawnow' command after 'hold off'
  3 Comments
Shivaputra Narke
Shivaputra Narke on 22 Jan 2019
Did you also try to set the 'Interruptible' property of axes to 'off' and 'BusyAction' to 'cancel' ?
As far as I understand from the question, it looks like the execution is queued.
wise_boss
wise_boss on 22 Jan 2019
I also found out that this happens because the WindowButtonDownFcn and ButtonDownFcn for the figure are activated when I click on the plot.
I have implemented the plot functions in the pushbutton_callback of the Play button. I'm guessing it gets interrupted as the above two functions are triggered, and since they are not callbacks, using the interruptible property didn't work. Do you have any means to surpress the WindowButtonDownFcn and ButtonDownFcn completely for the figure?
Thanks a lot!

Sign in to comment.


Jan
Jan on 22 Jan 2019
Edited: Jan on 22 Jan 2019
imshow(frame); shows the image in the current axes. If you click on an axes, e.g. handles.graph1, you make it active. Then
imshow(frame);
plot(handles.graph1,datam.t,datam.RFZ_NET,'-b',datam.t,datam.LFZ_NET,'-g');
creates the image inside handles.graph1 and overwrites it immediately by the plot command, which removes previously existing objects if hold is set to 'off'.
Solution: Create the axes for the image and define it explicitly as 'Parent'. In addition draw the diagram once only and reset the XData and YData only:
set(handles.graph1, 'NextPlot', 'add'); % As: hold on
Line1H = plot(handles.graph1, NaN, NaN, '-b');
Line2H = plot(handles.graph1, NaN, NaN, '-g');
tLineH = line(handles.graph1, [NaN, NaN], [-50,400], ...
'LineWidth', 2, 'Color', 'r')
ImageH = image([], 'Parent', ???)
% Or maybe:
ImageH = imshow(); % Adjust this to let the image appear, where you want it
for frameCount = start_frame:fast_f:max_frames
videoObject = handles.videoObject;
datam = handles.datam;
set(handles.text2,'String',['Frame: ' num2str(frameCount)]);
frame = read(videoObject,frameCount);
set(ImageH, 'CData', frame);
% Display plot
set(Line1H, 'XData', datam.t, 'YData', datam.RFZ_NET)
set(Line2H, 'XData', datam.t, 'YData', datam.LFZ_NET);
tik = frameCount* data_spf * spf_ratio;
set(tLineH, 'XData', [tik,tik]);
end
I do not know, where your want the image to appear, but I assume you can adjust this code to your needs.
  2 Comments
wise_boss
wise_boss on 22 Jan 2019
Thank you very much for the time for asnwering this question. I'll implement your answer to my code, meanwhile I also found out that this happens because the WindowButtonDownFcn and ButtonDownFcn for the figure are activated when I click on the plot.
I have implemented the plot functions in the pushbutton_callback of the Play button. I'm guessing it gets interrupted as the above two functions are triggered, and since they are not callbacks, using the interruptible property didn't work. Do you have any means to surpress the WindowButtonDownFcn and ButtonDownFcn completely for the figure?
Thanks, your support is awesome!
Adam
Adam on 23 Jan 2019
If they are empty they should not do anything.

Sign in to comment.

Categories

Find more on Specifying Target for Graphics Output 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!