Clear Filters
Clear Filters

How to create multiple interactive points using "impoint" in an array and get the position of the one I clicked on?

2 views (last 30 days)
I'm currently trying to generate n interactive points linked by a function using impoint and saving them in an array to extend the number of points if I want to. This was a topic before and a solution proposed by Giovanni Ughi doesn't work if I use the addNewPositionCallback like below (here as comment, you can remove % to try it):
[dim_y dim_x] = size(array); k = 0; for i = 10:10:dim_y % for example creating one every 10
k = k+1;
genio(k).h = impoint(gca,array(i,2),array(i,1));
% addNewPositionCallback(genio(k).h,@(genio(k).h) title(sprintf('(%1.0f,%1.0f)',genio(k).h(1),genio(k).h(2))));
% Construct boundary constraint function
fcn = makeConstrainToRectFcn('impoint',get(gca,'XLim'),get(gca,'YLim'));
% Enforce boundary constraint function using setPositionConstraintFcn
setPositionConstraintFcn(genio(k).h,fcn);
setColor(genio(k).h,'y');
end
If someone has solved that problem for a variable number of impoints I would be really grateful. Common solutions use Globals and are using copies for every impoint. Any suggestions?

Answers (0)

Community Treasure Hunt

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

Start Hunting!