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

4 vues (au cours des 30 derniers jours)
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

Réponses (1)

Flavio Palmieri
Flavio Palmieri le 4 Déc 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

Catégories

En savoir plus sur Modeling dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by