MATLAB Answers

Range Slider or Scroll Bar in App-Designer?

150 ビュー (過去 30 日間)
Till 2019 年 10 月 7 日
編集済み: Marek Svoboda 2021 年 4 月 9 日 13:26
I am plotting data over time and included a zoom function.
Is there any way to display the currently viewed data relatively to the complete data on a slider?
e.g: if my complete data is from 0 to 100 and i zoomed in showing the data from 10:90 it should look like this:
when zoomed in showing the data from 40 to 60 it should look like this:
A workaround i found was the range slider documented here:
But since i am trying to migrate my GUI to App-Designer the ways described on the page wouldn't work from my understanding
Thank you in advance
  2 件のコメント
Till 2019 年 10 月 9 日
Thank you very much, I decided to not use App Designer in the end and just used java components


回答 (1 件)

Marek Svoboda
Marek Svoboda 2020 年 2 月 10 日
編集済み: Marek Svoboda 2020 年 2 月 10 日
For anyone else who is trying to create a functioning range / double / two knob slider in App Designer: Yair's Range Sliders won't work because they use Java, which is not supported by App Designer. I played with it quite a bit and eventually came up with a creative solution that looks like this:
Essentially, it is a line ROI on top of a 1D axis. To implement it, first of all, include a "Panel" in your app GUI. The size of my panel is 40x280 px.
Then in your global properties and methods, you want to initiate the following items, respectively:
properties (Access = private)
ax; % for the axes
l; % for the line
methods (Access = private)
% Function that responds to the movement of the sliders
function lMoving(~, source)
% Always keep the position rounded to 1 decimal place
source.Position(1,1) = round(source.Position(1,1),1);
source.Position(2,1) = round(source.Position(2,1),1);
% Add any other action here triggered by the movement of the sliders
In the startupFcn, include the following:
% Create the 1D axes = axes( ...
app.Panel,'Color','none','YColor','none','XLim',[0,1.5],'YTick',[], ...
'XTick',0:0.5:1.5,'TickDir','both','TickLength',[0.03,0.035],'XMinorTick', ...
'on','Units','pixels','Position',[8,30,264,0] ...
% Disable the interactivity & toolbar visibility
disableDefaultInteractivity(; = 'off';
% Add the line ROI
app.l = images.roi.Line(,'Position',[0.9,0;1.1,0]);
% Add a listener that will trigger a callback function titled "lMoving" when user
% moves the ROI endpoints or the line ROI as a whole
Note that this range slider will not show up in the GUI until you actually run the app because it is drawn only as a part of the startupFcn.
In my implementation, I have the slider connected to two Numeric Edit Fields that mutually respond to changes in each other:
Hope you find it helpful!
  7 件のコメント
Marek Svoboda
Marek Svoboda 2021 年 4 月 9 日 13:25
@Jessica Angulo Capel This might be possible - I don't have the exact code handy, but there are definitely ways to assign keyboard input and so maybe a mouse wheel might work as well. More info on the KeyPressFcn here:
Just note that, from what I remember when I was looking into keyboard input, the app needs to be active (i.e., alrady previously selected/clicked on) for any keyboard input to work:
"This callback function executes when the user presses a key while UI figure or a child component has focus."
Also, in order to make this callback work, you may need to figure out the specific name of the keyboard/mouse button that you eventually want to be the trigger. For that, as a test, I recommend setting this callback to simply print the key name into a text field as you are pressing various keyboard keys. (Hope this makes sense! :))


Community Treasure Hunt

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

Start Hunting!

Translated by