How do I extract data from polyshape figures

5 Ansichten (letzte 30 Tage)
Cye
Cye am 10 Okt. 2018
Kommentiert: Steven Lord am 10 Okt. 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.

Antworten (1)

jonas
jonas am 10 Okt. 2018
Bearbeitet: jonas am 10 Okt. 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 Kommentar
Steven Lord
Steven Lord am 10 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Elementary Polygons finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by