Borrar filtros
Borrar filtros

How do I extract data from polyshape figures

4 visualizaciones (últimos 30 días)
Cye
Cye el 10 de Oct. de 2018
Comentada: Steven Lord el 10 de Oct. de 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.

Respuestas (1)

jonas
jonas el 10 de Oct. de 2018
Editada: jonas el 10 de Oct. de 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 comentario
Steven Lord
Steven Lord el 10 de Oct. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Elementary Polygons en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by