Start Stop button group not working

1 view (last 30 days)
Daniel Turon
Daniel Turon on 12 Aug 2022
Edited: Kevin Holly on 12 Aug 2022
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.

Answers (1)

Kevin Holly
Kevin Holly on 12 Aug 2022
Edited: Kevin Holly on 12 Aug 2022
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

Community Treasure Hunt

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

Start Hunting!

Translated by