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)
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일

0 개 추천

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

댓글 수: 4

I have the same question as for Stephen23 - How do you insert in App Designer the app's StartUpFcn?
In App Designer Component Browser, select the app then select Callbacks below that; you'll see StartupFcn; type a name to define a new StartupFcn.
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...)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품

릴리스

R2023a

질문:

2025년 2월 24일

댓글:

2025년 2월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by