So having failed to get this working for a week or so, I seem to have made it work with the right combination of while switch break etc.
Here's my solution in case it helps anyone:
% Generate some dummy data
x=[1:1:10];
for abc=1:8
for num=1:12
ydata(:,abc,num)=(x.^abc)*num;
end
end
% Plot 12x8
for abc=1:8
for num=1:12
y=ydata(:, abc,num);
plotpos=12*(abc-1)+num; % Converts the abc/num index into a single number which can be used to define the subplot
subplot(12,8,plotpos)
plot(x,y)
set(gca, 'Tag', num2str(plotpos)) % 'Tags' each plot with its plotpos index
end
end
brbr=1;
while brbr==1
try
w = waitforbuttonpress;
switch w
case 1 % keyboard
key = get(gcf,'currentcharacter');
if key==27 % (the Esc key)
close all
brbr=2;
break
end
if key=='1'
close
end
case 0 % mouse click
tag = get(gca,'tag');
tag=str2num(tag); % Converts 'tag' back to an abc and num index for the desired plot
% converting the 'tag' back to its abc num index - a bit clunky but it works...
num=mod(tag,12);
abc=floor(tag/12)+1;
if num==0
num=12;
abc=abc-1;
end
% Plotting the new figure (I do this via a separate script)
figure
y=ydata(:, abc,num); % Fetches (dummy) data again
plot(x,y)
end
catch; end % used try/catch to suppress an error when window closed by clicking the x
%fprintf('ended by script\n')
end