App Designer initial value for UserData for Slider

10 ビュー (過去 30 日間)
Andrei
Andrei 2025 年 2 月 24 日
コメント済み: Voss 2025 年 2 月 24 日
I want to return from a slider a different value than its Value property (that is, a value computed based on its Value).
In GUIDE, I would do this using the UserData propery, however, the App Designer GUI provides only the "Tag" property from the Identifiers section.
If I inspect the object in code I can see that there is a UserDate property available for the slider:
Position: [50 522 693 3]
Tag: ''
Tooltip: '30.5px'
Type: 'uislider'
UserData: []
Value: 0.3000
ValueChangedFcn: ''
ValueChangingFcn: @(source,event)executeCallback(ams,app,callback,requiresEventData,event)
Visible: on
I was thinking that I can initialize the UserData in the CreateFcn of the slider - but the slider comes only with ValueChangedFcn and ValueChangingFcn.
So how can I set an initial value to the UserData?
I'm using Matlab R2023a.
  3 件のコメント
Andrei
Andrei 2025 年 2 月 24 日
編集済み: Andrei 2025 年 2 月 24 日
@Stephen23 How do you insert the CreateFcn from AppDesigner?
The documentation also has UserData for the slider, but the App Designer does not provide a way to initialize it. The same for a way to directly add a CreateFcn for a slider object.
It is interesting the documentation for Adding App Designer Callbacks uses the Slider object as an example: Callbacks in App Designer
Only ValueChanged/ing Fcns seem to be available for sliders in AppDesigner.
(Last edit for minor typos)
Andrei
Andrei 2025 年 2 月 24 日
For the moment, I have a workaround: I moved the code that computes the needed value based on the slider's position into a separate function and I call that function each time that I need to use the output of the slider (what would have been the UserData).
In this way I can update the code for the slider without needing to make further changes in the app code. However, some transparency is lost with this - it would have been much easier to just set (easily) the initial value for the UserData.
As a note, I cannot prevent the user using the default slider position so the UserData is the empty array [ ] when the core function for the app is called.

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

採用された回答

Voss
Voss 2025 年 2 月 24 日

You can initialize the slider's UserData in the app's StartupFcn.

  4 件のコメント
Andrei
Andrei 2025 年 2 月 24 日
編集済み: Andrei 2025 年 2 月 24 日
Thank you, it worked. I was trying to add the function to the UIFigure, not to the app....
I will accept this answer, but I believe this needs to be posed as a feature request as the App Designer' GUI doesn't give access to all documented object properties / callbacks so the user is left with trying to figure out how to set them programmatically and this does not lead to self explanatory / concise code (just try to figure 2 years in the future where and why in the code the initial value of the property was set...)
Voss
Voss 2025 年 2 月 24 日

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by