Is there a way to add a button to a figure such that the next figure is displayed?

12 ビュー (過去 30 日間)
Dear reader,
For my work I often have to look at multiple figures I've plotted (in my case using imagesc(), but my questions is basically for all figures created). I have to compare the figures to each other, to find subtle differences. These are sometimes so subtle that a ctrl+tab command 'ruins' my concentration. I was wondering whether there's a button that I could add to the GUI of a figure that will open the next button.
Imagin you create two figures. The experience I'm looking for is the same that you'd have when closing one figure using the X button on the top right (using a Windows computer), so that you immediately see the next figure. But rather than closing the current figure, I just want it to move to the next (or previous?) one.
Kind regards,
Ariwan
  1 件のコメント
Ariwan Abdollah
Ariwan Abdollah 2020 年 11 月 14 日
編集済み: Ariwan Abdollah 2020 年 11 月 20 日
For any future reader, I added a 'b', that brings you to the previous figure. Also when some figures are closed, it nicely jumps to the next figure (so if you close figure 3, it will go from figure 2 to figure 4).
This script below is to see the effect. If you want to use it in your own script, use figure('keyPressFcn', @keyPressFcn) in your script when plotting or imaging something, create a file called keyPressFcn.m from with the script below, and comment out all the figures created below (so f1 - f6)
cheers!
f1 = figure('keyPressFcn', @keyPressFcn);
f2 = figure('keyPressFcn', @keyPressFcn);
f3 = figure('keyPressFcn', @keyPressFcn);
f4 = figure('keyPressFcn', @keyPressFcn);
f5 = figure('keyPressFcn', @keyPressFcn);
f6 = figure('keyPressFcn', @keyPressFcn);
function N(obj,eve)
if eve.Character == 'n'
h = findobj('type','figure');
A=zeros(1,length(h));
for i = 1:length(h)
A(i) = h(i).Number;
end
A=sort(A);
ix = find(A==obj.Number);
if ix == length(A)
n = A(1);
else
n = A(ix+1);
end
figure(n);
end
if eve.Character == 'b'
h = findobj('type','figure');
A=zeros(1,length(h));
for i = 1:length(h)
A(i) = h(i).Number;
end
A=sort(A);
ix = find(A==obj.Number);
if ix == 1
n = A(end);
else
n = A(ix-1);
end
figure(n);
end
end

サインインしてコメントする。

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 12 日
Here is a simple example. It creates 3 figures, and if you press 'n' key while focused on any window, it will open the next window
f1 = figure('KeyPressFcn', @keyPressFcn);
f2 = figure('KeyPressFcn', @keyPressFcn);
f3 = figure('KeyPressFcn', @keyPressFcn);
function keyPressFcn(obj, eve)
if eve.Character == 'n'
n = rem(obj.Number,3)+1;
figure(n);
end
end
  2 件のコメント
Ariwan Abdollah
Ariwan Abdollah 2020 年 11 月 13 日
Thank you very much, this is even better than I thought of!
Ameer Hamza
Ameer Hamza 2020 年 11 月 13 日
I am glad to be of help!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by