문제

How is it possible to get, directly from the Matlab command window, the position (i.e. the coordinates) of an object (e.g. an arrow, a rectangle or sim.) that I have drawn on a plot?

도움이 되었습니까?

해결책

You can usually do this using the handle graphics properties. For example:

Make a plot

h = plot(1:10, rand(10,1)); 

Then get the actual values of the points x = get(h,'xdata') y = get(h,'ydata')

Different types of objects have different properties, sometimes you have to explore. In that case this syntax is useful.

get(h)  %This displays all available properties on `h` to the command window

A final useful tidbit is the gco ("get current object") function, which provides the handle of the last item that you plotted or manually clicked on. This can help if you're not sure where the plotted item came from.


Edit:

To find all of the properties which are descendents of an object, use either findobj, or findall. For example:

findobj(gcf);  %Returns all non-hidden, typical objects.  This should be your first attempt.
findall(gcf);  %Returns all children, even hidden object, such as titles, manually added annotations, and UI menus

This call removes some common UI annotations

get(findall(gcf,'-not','type','uimenu','-not','type','uitoggletool','-not','type','uipushtool','-not','type','uitogglesplittool'),'type')

(Presumably the last example could be improved with a properly designed regexp, but I can't seem to get that working right now.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top