Flip vertical uislider such that negative values are displayed at the top
3 views (last 30 days)
Show older comments
In a appdesigner app, I have an uislider component. The callback of which controls a mechanical stage which moves in the vertical direction. The stages' coordinate system is intentionally such, that the positive values correspond to the stage being lowered.
Now, it seems to me like you cannot have an uislider component that has its positive values at the bottom and the negative ones at the top, can you? At least, I cannot flip the Limit-property...
3 Comments
Answers (1)
Image Analyst
on 14 May 2020
Why can't you just get the slider value, adjust it, and display it:
sliderValue = app.sldCoordinate.Value;
% Find out where the thumbbar is with respect to the max and min (top and bottom respectively).
range = app.sldCoordinate.Max - app.sldCoordinate.Min;
percentage = (sliderValue - app.sldCoordinate.Min) / range;
% Flip it
newSliderValue = app.sldCoordinate.Min + percentage * range;
% Set caption on some label
app.txtCoordinates.String = sprintf('Coordinate = %f', newSliderValue);
The above code is just off the top of my head and is untested.
2 Comments
Image Analyst
on 15 May 2020
I'm not using App Designer yet because, last time I checked, the debugging was difficult because the code window is in a different app than the workspace and command window, unlike the way it is with GUIDE. That's a deal breaker for me. I've talked in person with the App Designer developer team while I was at the Mathworks and they understood my reservations and I hope to think one day we'll be able to have them all in the same window.
Regarding #1, I'm not very familiar with App Designer, but as far as I know, I would expect every control to have a callback function. Are you saying that there is no callback function for the slider? Or that it vanishes after the GUI has fully loaded? Or just that there is no way to call it after the GUI has come up to set the caption properly? I did try to put a vertical slider on and reverse the max and min limits but it says that's not allowed. If it's a deal breaker for you, you can revert to GUIDE. I also suggest you call them and put it on the list of suggested feature enhancements. Please also mention my request for having workspace, code, and command panels all in one app, it you remember.
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!