Graphic objects and XData and YData
112 次查看(过去 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!