2014-03-13 27 views
1

我正在讨论从图中自动或从代码中获取点的y轴值。有什么方法可以得到实际的情节阅读?

比如我对剧情这一点:

enter image description here

如果我只在y轴有兴趣,我可以使用此代码来获得该点的Y轴值回我代码:

dcm_obj = datacursormode(figure(1)); 
set(dcm_obj,'DisplayStyle','datatip',... 
'SnapToDataVertex','off','Enable','on'); 
pause(); 
c_info = getCursorInfo(dcm_obj); 

但这样做的问题是,我必须手动干预,使用datacursormode,并点击该点。只有这样才能读取像素并了解其y值。

有没有反正我可以自动得到这个?我的意思是没有我干预的情节下的实际y值?

回答

3
>> h = plot((1:5).^2); %// example plot 
>> get(h,'YData') 
ans = 
    1  4  9 16 25 

或者,如果轴只有一个情节,你可以得到动态的手柄:

>> plot((1:5).^2); %// example plot 
>> get(get(gca,'Children'),'YData') 
ans = 
    1  4  9 16 25 
+1

当然'获得(得到(GCA, '孩子'), 'YDATA');' ?我无法检查,但它是'line' /'scattergroup'/etc。你想要的,而不是轴本身。 – Notlikethat

+0

@Notlikethat你说得对。你需要一个处理情节对象 –

+0

谢谢。那就是我正在寻找的东西。但是如果get(h,'Ydata')和get(get(gca,'Children'),'YData')'产生相同的结果,那么两者有什么区别?谁使用另一个?什么是“儿童”? – StuckInPhD

相关问题