File Exchange

image thumbnail

Mouse scroll wheel navigation

version 1.0.0.0 (1.9 KB) by Gus Brown
Navigate figures with the mouse scroll wheel.

2 Downloads

Updated 03 Mar 2008

View License

Tired of clicking the task bar to find the figure window that you want? So was I, so I decided to use the mouse scroll wheel as a way to change the current figure.

This function will update the figure WindowScrollWheelFcn so that the mouse scroll wheel can be used to cycle through figures.

It can also set the default figure create function to automatically activate this function when a new figure is created.

Cite As

Gus Brown (2020). Mouse scroll wheel navigation (https://www.mathworks.com/matlabcentral/fileexchange/18282-mouse-scroll-wheel-navigation), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (10)

Giorgio

Valerio Biscione

Nice code. However, I noticed that the order of scrolling is sometime different from the figure number properties (which is usually the order I look for).
For whoever have the same problem, I suggest to add a few lines.
Change the function figScroll to this one:

function figScroll(src,evnt)
% get figure handles and sort them
H = sort(get(0,'children'));
[~, in]=sort([H.Number]);
H=H(in);
if (evnt.VerticalScrollCount>0),
% scroll down
%F = find(H>src,1);
if isempty(find([H.Number]<src.Number,1)),
F=max([H.Number]);
else
F=find([H.Number]<src.Number,1,'last'); %valerio
end
else
% scroll up
%F = find(H<src,1,'last');
if isempty(find([H.Number]>src.Number,1)),
F=min([H.Number]);
else
F=find([H.Number]>src.Number,1); %valerio
end
end;
if isempty(F),
% jump to first or last figure
if (evnt.VerticalScrollCount<0),
figure(H(end));
else
figure(H(1));
end;
else
% goto next figure
figure(H(mod(F-1,length(H))+1));
end;
end

-tested with MATLAB 2014b-

Eric Diaz

Below is my workaround for similar functionality, however, not with the mouse wheel but rather the keyboard arrows.

function [TF] = GTscroll2006b(event,fig)
% GTscroll2006b Use the scroll wheel to navigate figure windows
%
% function GTscroll2006b(event,fig)
%
% Example:
%
% for n=1:length(imgfiles);
% figure(100+n);
% set(gcf,'position',pos1,'windowStyle','docked')
% imagesc(im1(:,:,n),[0 max(max(im1(:,:,workingImage)))]);hold on;
% end
%
% TF=1
%
% while TF == 1
% event = getkey
% TF = GTscroll2006b(event,gcf)
% end
%
% ************** Requires getkey from FileExchange***********************
% http://www.mathworks.com/matlabcentral/fileexchange/7465-getkey
% ***********************************************************************
%
% Esdiaz - Oct 2009

%% Cycle through figures
CH = get(0,'children');

H = sort(get(0,'children'));
if event == 28 || event == 31 % left or down arrow = scroll down
F = find(H<fig,1,'last');
elseif event == 29 || event == 30 % up or right arrow = scroll up
F = find(H>fig,1);
elseif event == 13
F=[];
end

if isempty(F),
% jump to first or last figure
if event == 28 || event == 31,
figure(H(1));
TF=1;
elseif event == 29 || event == 30
figure(H(end));
TF=1;
elseif event == 13
TF=0;
end;
else
% goto next figure
figure(H(mod(F-1,length(H))+1));
zoom;pause;
TF=1;
end;
%%
end

Eric Diaz

It would be nice if this worked with version 7.3.0 2006b, but, alas, it does not because as Matlab states..."There is no 'WindowScrollWheelFcn' property in the 'figure' class."

Is there any other solution?

Very nice idea Gus

I am struggling to find a way to make a scroll wheel modulate the frequency of a sound played by matlab. Would you happen to have an idea on how to proceed.

Best
Torben

Granzyme

Amazing function.
I had couple of questions Gus if you don't mind.
I am new to MATLAB (i'm a physician) and this is EXACTLY what I want - almost. I am trying to scroll through a whole stack of MRI images. So in order for this to work, I have to open lets say 25 seperate figure windows and then smoothly scroll through them. However - how can I just open ONE figure window and have ALL my images be scrolling through in it?

I am not much of a code write, but a nudge in the right direction will go a long way (meaning, i can use help function on MATLAB and attempt to write small code under your direction). Thanks!

snowdeer Î

very nice code. thanks!

Riccardo Meldolesi

I must confess I haven't looked through the code, but the GREAT usefulness of this plugin deserves top marks. Well done!

Gus Brown

Good point. I guess I never intended for one to scroll through a limited set of figures, rather all figures. As such when one uses the mouse scroll wheel, the function fetches all the current figures and then chooses the next one.
The option to apply the scroll function to only one figure is there so that the function can be run on new figures.

Jiro Doke

Very nice idea.

One comment. You have it so that you can specify the figure handles to apply this functionality (it wasn't clear in the help that you can supply multiple figure handles). But when scrolling, it always scrolls to the next (or previous) figure of all the figures, not just the ones specified. This causes the scroll to halt when it lands on a figure that I didn't specify. For example:

for id = 1:10;
figure;plot(rand(10,id));
end
GTscroll([1 4 6 8 10])

Scrolling down from 10 takes me to figure 9, and then I can't scroll up or down from there because I didn't specify that figure.

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: DOCK and UNDOCK figures into groups

Community Treasure Hunt

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

Start Hunting!