How do I extract data from polyshape figures

7 vues (au cours des 30 derniers jours)
Cye
Cye le 10 Oct 2018
Commenté : Steven Lord le 10 Oct 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.

Réponses (1)

jonas
jonas le 10 Oct 2018
Modifié(e) : jonas le 10 Oct 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 commentaire
Steven Lord
Steven Lord le 10 Oct 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Elementary Polygons 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