フィルターのクリア

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

2 ビュー (過去 30 日間)
Brian
Brian 2023 年 1 月 13 日
回答済み: Image Analyst 2023 年 1 月 13 日
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 Center および File ExchangeVisual Exploration についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by