Axes Click in GUI interrupts Figure Plot
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
1 Commento
Adam
il 22 Gen 2019
Modificato: Adam
il 22 Gen 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.
Risposte (2)
Shivaputra Narke
il 21 Gen 2019
check using 'drawnow' command after 'hold off'
3 Commenti
Shivaputra Narke
il 22 Gen 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.
Jan
il 22 Gen 2019
Modificato: Jan
il 22 Gen 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 Commenti
Vedere anche
Categorie
Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!