App Designer initial value for UserData for Slider

5 Ansichten (letzte 30 Tage)
Andrei
Andrei am 24 Feb. 2025
Kommentiert: Voss am 24 Feb. 2025
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 Kommentare
Andrei
Andrei am 24 Feb. 2025
Bearbeitet: Andrei am 24 Feb. 2025
@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 am 24 Feb. 2025
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Voss
Voss am 24 Feb. 2025

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

  4 Kommentare
Andrei
Andrei am 24 Feb. 2025
Bearbeitet: Andrei am 24 Feb. 2025
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...)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by