문제

I'm talking about getting the y-axis value of a point from the plot automatically or from code.

For example I have this point on plot:

enter image description here

If I am only interested in its y-axis I can use this code to get the y-axis value of this point back to my code:

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

But the problem with this is that I have to manually intervene, use the datacursormode, and click on the point. Only then will the pixel be read and its y-value understood.

Is there anyway I can get this automatically? I mean the actual y-value from the plot without me intervening?

도움이 되었습니까?

해결책

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

Or, if the axis only has that one plot, you can get its handle dynamically:

>> plot((1:5).^2); %// example plot
>> get(get(gca,'Children'),'YData')
ans =
     1     4     9    16    25
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top