Azzera filtri
Azzera filtri

Matlab GUI break while loop behavior change

3 visualizzazioni (ultimi 30 giorni)
Quentin
Quentin il 27 Giu 2018
Commentato: Quentin il 27 Giu 2018
Hello Everyone,
I have a quick question. We have some Matlab code in the lab that we've been using for many years now, but only suddenly have we started having problems. It is basically a gui that scrolls through frames of a video where users can annotate animal behavior. The code was written on Matlab 2014 and still works fine on that version. We've noticed that in both Matlab 2016 and Matlab 2017, it no longer works. Prior to the update, when students would press a gui button, the callback function would break a while loop and pause the video. This was in Matlab 2014. So it's as if even the code was executing a while loop, it would still listen for callbacks. Now in Matlab 2016 and Matlab 2017, it waits for the while loop to entirely complete before responding to the call back. Is this normal and is there a way I can change this behavior? Thank you. I've attached the part of the code that contains the callback and the while loop. I'm not sure if it will help.
Quentin
% --- Executes on button press in playButton.
function playButton_Callback(hObject, eventdata, handles)
% hObject handle to playButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of playButton
global microMovie;
global gray_mean_frame;
global trx;
global frameSize;
set(handles.previous,'Enable','off');
set(handles.next,'Enable','off');
set(handles.accept,'Enable','off');
set(handles.decline,'Enable','off');
color_matrix = [1 0 1; 0 1 0; 1 1 0; 0 1 1; 0 0 1; 1 0 0; 0 1 0; 1 0 1; 1 1 1; 0 0 0;.5 .5 .5];
playButtonStatus = get(hObject,'Value');
if playButtonStatus == 0
set(handles.playButton, 'String', 'Play');
elseif playButtonStatus == 1
set(handles.playButton, 'String', 'Pause');
frameNumber = str2double(get(handles.inputFrameNumber,'String'));
while playButtonStatus == 1 && frameNumber <= trx(1).nframes
tic;
playButtonStatus = get(hObject,'Value');
switch get(get(handles.playBackSpeedGroup,'SelectedObject'),'Tag');
case 'One_Ex', frameSkip = 1;
case 'Two_Ex', frameSkip = 2;
case 'Five_Ex', frameSkip = 5;
case 'Ten_Ex', frameSkip = 10;
case 'TwentyFive_Ex', frameSkip = 25;
case 'Fifty_Ex', frameSkip = 50;
end
movieFrame = gray_mean_frame;
%linearInd = microMovie(:,1,frameNumber) + (microMovie(:,2,frameNumber)-1)*frameSize(1);
linearInd = sub2ind(frameSize,microMovie(:,1,frameNumber),microMovie(:,2,frameNumber));
movieFrame(linearInd) = microMovie(:,3,frameNumber);
axes(handles.frameAxis);
cla;
imshow(movieFrame);
for i = 1:size(trx,2)
hold on; plot(trx(i).head_x(frameNumber), trx(i).head_y(frameNumber), 'o', 'color', color_matrix(i,:));
hold on; plot(trx(i).xwingl(frameNumber), trx(i).ywingl(frameNumber), '.', 'color', color_matrix(i,:));
hold on; plot(trx(i).xwingr(frameNumber), trx(i).ywingr(frameNumber), '.', 'color', color_matrix(i,:));
hold on; ellipse(2 * trx(i).a(frameNumber), 2 * trx(i).b(frameNumber), ...
trx(i).theta(frameNumber), trx(i).x(frameNumber), trx(i).y(frameNumber), color_matrix(i,:));
end
frameNumber = frameNumber + frameSkip;
set(handles.inputFrameNumber, 'String', num2str(frameNumber));
set(handles.frameNumberSlider,'Value', frameNumber);
if frameSkip == 1 || frameSkip == 2 || frameSkip == 5 || frameSkip == 10
elapsedTime = toc;
pause(.033/frameSkip - elapsedTime);
elseif frameSkip == 25 || frameSkip == 50
frameNumber = frameNumber + frameSkip - 1;
end
end
end

Risposta accettata

Jan
Jan il 27 Giu 2018
Modificato: Jan il 27 Giu 2018
Try to insert a drawnow.
By the way:
axes(handles.frameAxis);
cla;
imshow(movieFrame);
This is inefficient. Faster:
imgH = gobject(0); % before the loop
handles.frameAxis.NextPlot = 'add';
...
if isempty(imgH)
imgH = imshow(movieFrame);
else
imgH.CData = movieFrame;
end
It is much cheaper to replace the CData of an existing image instead of deleting and recreating the image.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps 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!

Translated by