How do I extract data from polyshape figures

8 visualizzazioni (ultimi 30 giorni)
Cye
Cye il 10 Ott 2018
Commentato: Steven Lord il 10 Ott 2018
I know how to extract data from a regular figure, e.g., open('example.fig'); a = get(gca,'Children'); xdata = get(a, 'XData'); ydata = get(a, 'YData');
However, I'm stuck when it comes to figures that were created with polyshapes.

Risposte (1)

jonas
jonas il 10 Ott 2018
Modificato: jonas il 10 Ott 2018
If you are looking to extract the polyshape, then it's stored in the polygon object's shape property.
So for example
% Plot polygon
p=polyshape([0 1 1 0],[0 0 1 1])
plot(p)
% Extract
ax=gca;
ax.Children.Shape
  1 Commento
Steven Lord
Steven Lord il 10 Ott 2018
I would use findobj instead of assuming that gca still refers to the axes in which the polyshape was plotted and that the axes only has one child. [For purposes of this example I do make the assumption that only one polygon was plotted, so if we find one it's the right one, but you could test that poly1 isscalar and handle the cases where it is not appropriately.]
>> p=polyshape([0 1 1 0],[0 0 1 1]);
>> plot(p);
>> poly1 = findobj(groot, 'type', 'polygon');
>> p2 = poly1.Shape;
>> isequal(p, p2)
ans =
logical
1
As written this code will find all polygon objects you've plotted because it looks for everything under groot. You can change that first input to search in just a particular figure or axes.

Accedi per commentare.

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!

Translated by