Calling back the previous value of the GUI slider

2 ビュー (過去 30 日間)
Munir Suleman
Munir Suleman 2019 年 6 月 21 日
回答済み: Geoff Hayes 2019 年 6 月 22 日
Hi all
I'm new to Matlab GUI. I'm trying to get the initial position of the slider before the person clicks on the arrows or drags the slider.
I want to be able to get the change in the slider position (dt) and since I can already get the end position of the slider from the callback, how do I get the previous position?
Is addlistner the solution? If so I have no idea how it works so an explanation would be very helpful :)
Alternatively, I know the value is only given in the callback when the user unclicks the mouse from the slider. Is there a way to get the slider value when the user clicks the slider? (i.e. the starting position of the slider)
Thank you

回答 (1 件)

Geoff Hayes
Geoff Hayes 2019 年 6 月 22 日
Munir - you haven't said whether you are using GUIDE, App Designer, or programmatically creating your GUI, but in all three cases, you would want to do something like
  1. On GUI start, save the initial position of the slider (to the handles structure if using GUIDE, or as a property if using App Designer)
  2. When the slider callback fires, get the new position of the slider and calculate the difference with that of the initial position (stored in the handles strcuture or as a property).
  3. Replace the previously stored position of the slider with the new position.
In this manner, you will always have the last known position of the slider.

カテゴリ

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