Enlarging a subplot via mouse click (multiple times)?

7 次查看(过去 30 天)
I have searched but haven't found an answer that fits my use case. I have a script that imports data from a 96-well plate reader. I then plot data from each well on the screen as a 12x8 grid via the subplot command (actually, subplot_tight but I don't think that matters). I want to be able to click (or double click, or ctrl-click or something) on a subplot, and have it run a second script that plots the data in more detail with some calculations (I already have this script). I feel like I'm 90% of the way there but I can't get my script to repeat.
What I have done so far: I use the index of the well (a letter and a number index) to define where to put the subplot. Each plot in the 12x8 view is 'tagged' with this information. Then by clicking on it, I retrieve that information and use that to plot it again in full size.
What I would like to be able to do would be to do this several times over. E.g. load up the 12x8 view, click on the interesting subplots, view that one in a separate window, then close that window and select another. Perhaps I could hit Esc to exit the waitforbuttonpress and close all the viewing windows?
Any ideas?
% 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
try
w = waitforbuttonpress;
switch w
case 1 % keyboard
key = get(gcf,'currentcharacter');
if key==27 % (the Esc key)
close all
%break
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 actually want to 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

采纳的回答

Superficial
Superficial 2020-10-7
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by