Position property of Polygon object created in Live Script does not update when moved interactively.
Show older comments
I get different results depending on whether I enter commands directly in the command window or in a Live Script. I've described two scenarios below and hope someone knows why they give different results.
In the first scenario, I enter the following commands directly in the command window:
im = imread("peppers.png");
h = imshow(im);
p = drawpolygon(h.Parent, 'position', [100 100; 300 100; 300 200; 100 200]);
The figure appears in a new window as expected. I then interactively move the polygon to a new position within the figure. After moving the polygon, I look at its position using:
p.Position
and get
ans =
276 261
476 261
476 361
276 361
The polygon's position has updated to the location where I moved it.
In the second scenario, I enter the same 3 inital commands to create the figure and polygon in a Live Script and run it. I see the figure in the Live Script and can move the polygon as before. However, when I look at p.Position in the workspace, I get the polygon's original position:
ans =
100 100
300 100
300 200
100 200
(Side note: I'm not sure why the spacing of the two ans values is different. I didn't explicity change any formatting.)
If I look at p.Position in a new section of the Live Script and run that section separately, It also gives the original position, eventhough I can see the polygon is in a different position from where it started.
Please explain what's going on and what to change so that I can use an interactive polygon in a Live Script.
2 Comments
Zinea
on 9 Apr 2024
The value of p.Position is changing for me even for the second scenario using Live Script. What MATLAB version are you using?
Steven Martin
on 10 Apr 2024
Accepted Answer
More Answers (0)
Categories
Find more on Printing and Saving 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!
