フィルターのクリア

How to add replay button?

4 ビュー (過去 30 日間)
Lavanya
Lavanya 2022 年 6 月 10 日
コメント済み: Voss 2022 年 6 月 15 日
Here I am enclosing the .m file, in which I have created a play button i.e auto scroll of the Slider with images and Stop Button as well . But I wanted to create a button to replay button which can play the slider again. Is there any way for this?

採用された回答

Voss
Voss 2022 年 6 月 10 日
編集済み: Voss 2022 年 6 月 10 日
Create a new button:
h.replaybutton = uicontrol( ...
'Parent',h.f, ...
'Units','normalized', ...
'Position',[0.8 0 0.1 0.1], ...
'BackgroundColor',[1 1 1], ...
'String','Replay', ...
'Callback',@replaybuttonCallback);
In its callback function, reset the slider Value to the Min, and then execute the Play button callback:
function replaybuttonCallback(~,~)
set(h.slider,'Value',get(h.slider,'Min'));
buttonCallback();
end
That should give you "replay" functionality.
By the way, this
if sliderValue < (get(h.slider, 'Max') - get(h.slider, 'Min'))
should be this
if sliderValue < get(h.slider, 'Max')
Otherwise, the montages stop when N=99 instead of N=100.
Maybe you had it like that at one point but had a problem when the slider's Value was its Max. That happened because the Value was not exactly an integer, which can happen because of floating-point precision or because the user has interacted with the slider directly. In any case, you can avoid that problem by rounding the slider Value when you set it:
set(h.slider, 'Value', round(sliderValue + 1));
and you may want to change the slider's SliderStep to control how the Value changes when the user clicks it.
  4 件のコメント
Lavanya
Lavanya 2022 年 6 月 15 日
Yes, Can we add buttons for to speed up and slow down the play button?
Voss
Voss 2022 年 6 月 15 日
Yes, modifying the timer's Period would change the playback rate, but you cannot modify the Period while the timer is running, so you'd have to stop the timer, set the Period, and start the timer again.
For instance, a function like this would increase the timer's Period by 10% every time the function runs (which would decrease the playback rate by 10%):
function slowDownCallback(hObject,eventdata)
was_running = strcmp(h.RandTimer.Running,'on')
if was_running % stop the timer if it is running
stop(h.RandTimer);
end
h.RandTimer.Period = h.RandTimer.Period*1.1; % set the period
if was_running % re-start the timer if it was running
start(h.RandTimer);
end
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by