Azzera filtri
Azzera filtri

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

9 visualizzazioni (ultimi 30 giorni)
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 Commenti
Tom DeLonge
Tom DeLonge il 14 Mag 2020
Yes, thanks, I understand I could do that. But in that case, an incorrect coordinate system is displayed...
Geoff Hayes
Geoff Hayes il 14 Mag 2020
Where is the coordinate system displayed that you cannot correct it?

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 14 Mag 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 Commenti
Tom DeLonge
Tom DeLonge il 15 Mag 2020
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 il 15 Mag 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.

Accedi per commentare.

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by