Plot a column from an array by clicking on an image of that array

2 次查看(过去 30 天)
Say I have an array an image of which I can display:
ti = magic(32);
figure(1);
imagesc(ti);
I want to be able to click on a pixel in the image frame and have a plot updated to show the column from the original array that includes that pixel.
while 1
figure(1);
[x,y] = ginput;
figure(2);
plot(ti(:,round(x)));
end
Except that this doesn't work.
What I really want is a tool in an image figure which plots the columnar profile if I click the tool on the image.
Thanks.

采纳的回答

Image Analyst
Image Analyst 2023-1-13
Try this:
ti = magic(32);
subplot(2, 1, 1);
imshow(ti, [], 'InitialMagnification', 1000)
g = gcf;
g.WindowState = 'maximized';
buttonText = 'OK';
while strcmpi(buttonText, 'OK')
subplot(2, 1, 1);
promptMessage = sprintf('Click a point');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'OK', 'Quit', 'OK');
if contains(buttonText, 'Quit', 'IgnoreCase', true)
return; % or break or continue.
end
[x, y] = ginput(1);
column = round(x);
thisColumn = ti(:, column);
subplot(2, 1, 2);
plot(thisColumn, 'b-', 'LineWidth', 2);
grid on;
caption = sprintf('Column %d', column);
title(caption, 'FontSize', 16)
xlabel('Row', 'FontSize', 16)
ylabel('Value', 'FontSize', 16)
end

更多回答(0 个)

类别

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

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by