MATLAB Answers

Range Slider or Scroll Bar in App-Designer?

146 views (last 30 days)
Till
Till on 7 Oct 2019
Edited: Marek Svoboda on 9 Apr 2021 at 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:
slider2.png
when zoomed in showing the data from 40 to 60 it should look like this:
slider.png
A workaround i found was the range slider documented here: http://undocumentedmatlab.com/blog/sliders-in-matlab-gui
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 Comments
Till
Till on 9 Oct 2019
Thank you very much, I decided to not use App Designer in the end and just used java components

Sign in to comment.

Answers (1)

Marek Svoboda
Marek Svoboda on 10 Feb 2020
Edited: Marek Svoboda on 10 Feb 2020
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
end
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
end
In the startupFcn, include the following:
% Create the 1D axes
app.ax = 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(app.ax);
app.ax.Toolbar.Visible = 'off';
% Add the line ROI
app.l = images.roi.Line(app.ax,'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
addlistener(app.l,'MovingROI',@(varargin)lMoving(app,app.l));
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 Comments
Marek Svoboda
Marek Svoboda on 9 Apr 2021 at 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! :))

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!