App Designer initial value for UserData for Slider

10 visualizaciones (últimos 30 días)
Andrei
Andrei el 24 de Feb. de 2025
Comentada: Voss el 24 de Feb. de 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 comentarios
Andrei
Andrei el 24 de Feb. de 2025
Editada: Andrei el 24 de Feb. de 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 el 24 de Feb. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Voss
Voss el 24 de Feb. de 2025

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

  4 comentarios
Andrei
Andrei el 24 de Feb. de 2025
Editada: Andrei el 24 de Feb. de 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...)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by