Flip vertical uislider such that negative values are displayed at the top

4 次查看(过去 30 天)
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 个评论
Tom DeLonge
Tom DeLonge 2020-5-14
Yes, thanks, I understand I could do that. But in that case, an incorrect coordinate system is displayed...

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2020-5-14
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 个评论
Tom DeLonge
Tom DeLonge 2020-5-15
Thanks, Image Analyst. It is indeed possible to change the ticklabels via
app.slider.MajorTickLabels = sprintfc('%1.1f',app.slider.MajorTicks);
Two problems with this "hack":
  1. If you put above line in the startupFcn, you need to wait until the GUI has fully loaded. AFAIK there is no callback function after the GUI has loaded.
  2. You need to change every occurence where the app accesses app.slider.Value and add a minus
Probably the best solution so far...
Image Analyst
Image Analyst 2020-5-15
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by