Position property of Polygon object created in Live Script does not update when moved interactively.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Zinea
il 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?
Risposta accettata
Arun
il 17 Apr 2024
Modificato: Arun
il 17 Apr 2024
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 Commenti
Arun
il 17 Apr 2024
@Steven Martin the screenshot represents the output for a similar code. Happy to Help.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Elementary Polygons in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!