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

조회 수: 4 (최근 30일)
Tom DeLonge
Tom DeLonge 2020년 5월 14일
댓글: Image Analyst 2020년 5월 15일
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...
Geoff Hayes
Geoff Hayes 2020년 5월 14일
Where is the coordinate system displayed that you cannot correct it?

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

답변 (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