How to update position of impoly vertices using setPosition within addNewPositionCallback?

3 views (last 30 days)
Hi, I'm having difficulty with setPosition when used inside addNewPositionCallback with impoly. The vertices are not updating their position when a point is dragged. In this case vertex 5 remains unchanged when vertex 1 is dragged. Please see base example code below.
poly=[ -136 115; 40 115; 216 115; 216 15; 216 -185; 40 -185; -136 -185; -136 15];
figure
p = impoly(gca, poly) ;
addNewPositionCallback(p,@(pos)updatePos(pos));
function updatePos(pos)
upDate=pos;
upDate(5,:)=upDate(1,:);
setPosition(p,upDate);
end
end

Answers (1)

Flavio Palmieri
Flavio Palmieri on 4 Dec 2017
You need to pass p parameter in the callback function like this:
addNewPositionCallback(p,@(pos)updatePos(p,pos));
and then edit the function:
function updatePos(p,pos)
upDate=pos;
upDate(5,:)=upDate(1,:);
setPosition(p,upDate);
end

Categories

Find more on Modeling 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!