Plot a column from an array by clicking on an image of that array
3 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Image Analyst
on 13 Jan 2023
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 Comments
More Answers (0)
See Also
Categories
Find more on Errorbars in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!