Position property of Polygon object created in Live Script does not update when moved interactively.
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Zinea
2024년 4월 9일
The value of p.Position is changing for me even for the second scenario using Live Script. What MATLAB version are you using?
채택된 답변
Arun
2024년 4월 17일
편집: Arun
2024년 4월 17일
Hi Steven,
I understand that the position of the polygon object is updated in the workspace when the object, created using command window is relocated. However, this does not occur when using Live Script for the same purpose.
This is because the Live Editor is using a cloning mechanism to present its figures. Essentially, when a figure is created within a Live Script, it undergoes a procedure that results in a clone of the original figure being embedded in the Live Script.
For example, if you run the following code in the Live Editor:
f = figure;
ax = axes(f);
plot(ax,1:10)
and zoom/pan the axes, the values of XLim/YLim of the axes stores in the variable ax won't change. This is because the displayed figure is not the figure that was created during the execution, but a copy of that figure.
Similarly, when the user gets the Position property of drawpolygon, this is not the object that was interactively changed but the copy of that object was interactively modified.
The figure outputs in the Live Editor are not directly accessible to the user, but it is still possible to get them and query certain properties if needed, for example:
f = findall(0,'type','figure','Visible','on');
p=findobj(f,'type',"images.roi.polygon"); % assuming there is one visible figure
p.Position % this is the Position value of the modified polygon
For more information related to "Live Scripts and Functions" please refer the share documentation link:
Hope this helps.
댓글 수: 2
Arun
2024년 4월 17일
@Steven Martin the screenshot represents the output for a similar code. Happy to Help.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Elementary Polygons에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!