How to use horizontal sliders to slide and show multiple axes
Show older comments
Hello everyone,
I am new to the GUI development. I have 8 axes in my GUI, which are too busy to display them all at one time. I want to add a horizontal slider at the bottom of the GUI to allow users to slide back and forth to see the figures, which is supposed to work as the scroll bars in windows.
My questions: 1. How to set the dimension of the visible part of the GUI to be the same size of my computer screen. 2. How to link to the values to the sliders?
Any example code available? My project is time sensitive. Do appreciate to your help.
Thanks
Many Thanks
Answers (3)
Jan
on 20 May 2011
1 vote
- WindowAPI(FigH, 'maximize'): Figure fills the screen with border and menu bar
- WindowAPI(FigH, 'screen'): Figure contents fills the screen, not border, no menubar
- WindowAPI(FigH, 'fullscreen'): Figure contents fill the full screen, even the Windows taskbar is hidden.
Fangjun Jiang
on 19 May 2011
0 votes
I am not sure if it can be done. This post may give you an idea since your problem is that you don't have enough space in your GUI real estate.
3 Comments
Matt Fig
on 19 May 2011
newtomat says,
Thanks for your reply. The other question is how to get the values and link them to the slider values. Thanks
Matt Fig
on 19 May 2011
Fangjun Jiang says,
I don't have an example that is right fit for you exactly. I thought your "not enough space problem" could be solved by using the tab panel (if you are lucky enough to have Matlab R2011a). Otherwise, the method described in the other post using ListBox could also work. Of course, it may not be that easy for you since you just start leaning GUI development. Follow the demonstrations and examples provided by Matlab, you should be able to get there.
newtomat
on 19 May 2011
Matt Fig
on 19 May 2011
Here is an example:
function [] = slider_ex()
% Help goes here.
Sz = get(0,'screensize');
S.fh = figure('units','pixels',...
'position',[10 30 Sz(3)-10 Sz(4)-60],...
'menubar','none',...
'name','slider_ex',...
'numbertitle','off',...
'resize','off');
S.sl = uicontrol('style','slide',...
'unit','pix',...
'position',[80 20 Sz(3)-150 40],...
'min',1,'max',8,'val',1,...
'SliderStep',[1/7 1/7]);
S.ax = axes('units','pix','pos',[80 100 Sz(3)-150 Sz(4)-240]);
% Now make some data. Your data may be different, but the approach is the
% same...
x = 0:.01:1;
hold on
for ii = 1:8
S.L(ii) = plot(x,x.^ii);
end
set(S.L(2:8),'visible','off'); % Make all but one line invisible.
S.CUR = 1; % Store the currently visible line.
S.LEG = legend('x^1');
set(S.sl,'call',{@sl_call}); % Set the Callback.
guidata(S.fh,S); % Save S for later...
function [] = sl_call(varargin)
% Callback for the slider.
S = guidata(gcbf); % Get the stored data.
set(S.L(S.CUR),'visible','off')
V = get(S.sl,'val');
set(S.L(V),'visible','on')
set(S.LEG,'string',['x^',num2str(V)])
S.CUR = V;
guidata(gcbf,S) % Save the updated structure.
5 Comments
newtomat
on 19 May 2011
Matt Fig
on 19 May 2011
As I mentioned above, the approach would be the same for different situations. You will have to work it out for yourself based on my example, as I cannot take the time to come up with a new example for every tweak you may think of next...
Fangjun Jiang
on 19 May 2011
Matt,
What's up with the comments in my answer above? Those two "newtomat says," and "Fangjun Jiang says," lines? Did you edit the comments? Just curious.
Matt Fig
on 19 May 2011
Hello Fangjun,
Yes, I was getting rid of a non-answer given by newtomat and your comment on that non-answer. newtomat's non-answer was really a comment on your answer, so...
Unfortunately, editors cannot move an answer to a comment with the same authorship as of now.
Fangjun Jiang
on 19 May 2011
Thank you for the clarification. Now I remembered.
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!