Start Stop button group not working

5 次查看(过去 30 天)
I am making a 3D cube viewer in matlab, and need a start stop button to automatically flip through the cube. I have the following code...
function PlayPauseButtonGroupSelectionChanged(app, event)
mode = app.PlayPauseButtonGroup.SelectedObject;
if mode == app.PlayButton
app.playMode = true;
disp('play')
app.playNow
end
if mode == app.PauseButton
app.playMode = false;
disp('pause')
end
while app.playMode
app.currentChannel = app.currentChannel+1;
if app.currentChannel>app.Nv
app.currentChannel = 1;
end
app.ChannelSlider.Value=app.currentChannel;
app.refreshAxes;
pause(0.4);
if ~isvalid(app); break; end %Prevents an error caused by this loop trying to continue with a closed figure
end
end
The issue I believe falls in a second instance of the buttons callback not being to be activated whilst it is still running. When I am flipping between the play/pause, it is not displaying 'play' or 'pause' as it should be. Is there a way to fix this? I have interruptible checked on.

回答(1 个)

Kevin Holly
Kevin Holly 2022-8-12
编辑:Kevin Holly 2022-8-12
The function works for me. pause and play are displayed in the command window. Please see testpauseplay app attached.
If you want a play/stop button for your slider, you could use a pushbutton and change it's text and icon after being clicked.
See video player app attached if that is something you would be interested in (snippet of code below).
if app.PlayButton.Text == "Play"
app.PlayButton.Text = "Stop";
app.PlayButton.Icon = "IconEnd.png";
while hasFrame(app.vidObj)
vidFrame = readFrame(app.vidObj);
imshow(vidFrame,'Parent',app.UIAxes)
pause(1/app.vidObj.FrameRate);
if app.PlayButton.Text == "Play"
disp('Loop stopped by user');
break;
end
end
else
app.PlayButton.Text = "Play";
app.PlayButton.Icon = "IconPlay.png";
end

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by