Graphic objects and XData and YData
조회 수: 113 (최근 30일)
이전 댓글 표시
I can't even describe a problem well because of my ignorance in this subject. Here's what I'm trying to do:
I have a figure with bunch of objects on it such as text, line that contains the data being plotted, and groups created by imline.
Now, I have to perform an analysis with Xdata and YData from the axis. So, I'm doing this:
axis_h = findobj(gcf,'Type','axes');
Then, I do the following:
obj_h = get(axis_h,'Children');
So, I get the following:
3x1 graphics array:
Text (\DeltaY/\DeltaX = 27719.3352 [\DeltaX = 0.01788, \DeltaY = 495.62…)
Group (imline)
Line (Fp\_ext vs. Xp\_UPR (ez5 rud revJ.dyn stiff singlePCU nom OR dmp 0p01…)
Now I need to get XData and YData from Line graphic array and I don't know how.
I tried the following:
line = findobj(obj_h,'Type','line');
So, I get the following:
5x1 graphics array:
Line (Fp\_ext vs. Xp\_UPR (ez5 rud revJ.dyn stiff singlePCU nom OR dmp 0p018…)
Line (end point 2)
Line (end point 1)
Line (top line)
Line (bottom line)
The same problem, I don't know how to get XData and YData from the first line object only.
I don't want to do obj_h(3) or line(1) to get XDat and YData because I don't think it's robust.
What is the robust way of getting XData and YData from "Line (Fp\_ext vs. Xp\_UPR (ez5 rud revJ.dyn stiff singlePCU nom OR dmp 0p01…)"?
Can anyone help me, please?
Thank you,
Eric
댓글 수: 4
Image Analyst
2015년 9월 6일
Why do you not already have the x and y data? After all, you created the figure by using them, didn't you? If not, how did you lose them?
답변 (1개)
Geoff Hayes
2015년 9월 5일
Eric - if you are plotting one or more lines or objects created by imline, then why not just save the handle to the graphics objects that you are plotting to the figure? For example,
x = -pi:0.1:pi;
y = sin(x);
h = plot(x,y);
The above code will draw the sine curve to my figure. The h is the handle to the graphics object created by plot. I can now manipulate this object as follows:
xdata = get(h,'XData');
ydata = get(h,'YData');
set(h,'YData',ydata+1);
So if you "save" the handles to these objects as you draw/plot them, then you shouldn't have to use findobj to find that handle that you are interested in.
댓글 수: 2
Mike Garrity
2015년 9월 9일
Yes, it is a good idea to keep the return value from plot if you're going to want to modify the data. As a wise man once said:
They're called handles because you're supposed to
hold on to them.
But if you do need to use findobj to find a handle that you haven't kept track of, then there are a lot of options that might be useful. The most common one in your situation is to have your plotting function set the Tag property of the line objects it creates. Then you can use something like this
findobj(gca,'Tag','MyPlot')
to find them.
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!