Cursor mode only for specified data

조회 수: 2 (최근 30일)
fjnb86
fjnb86 2011년 10월 21일
Hello everybody,
I have one figure with two plots. One of them is a scatter plot and I want activate the data cursor and only find points of this data.
I dont know how to really modify using myfunction
Maybe creating a specific handle?
Thanks
Code:
function scatterMod(varargin)
scatter(varargin{:}) %this is the data which I want to work using the data cursor
dcm = datacursormode(gcf);
set(dcm, 'updatefcn', @myfunction)
function output_txt = myfunction(obj,event_obj)
% Display the position of the data cursor
% obj Currently not used (empty)
% event_obj Handle to event object
% output_txt Data cursor text string (string or cell array of strings).
pos = get(event_obj,'Position');
output_txt = {['X: ',num2str(pos(1),4)],...
['Y: ',num2str(pos(2),4)]};
% If there is a Z-coordinate in the position, display it as well
if length(pos) > 2
output_txt{end+1} = ['Z: ',num2str(pos(3),4)];
end

채택된 답변

Walter Roberson
Walter Roberson 2011년 11월 15일
Try setting HitTest off on the points you do not want data cursor to work for. (I don't promise it will work, but it is worth the experiment.)
  댓글 수: 1
fjnb86
fjnb86 2012년 4월 25일
It was many time ago but you were right!
Until now I was doing other thinh but yours is more elegant and today (with more experience) I solved!
%code for other new users
[handlesfigure]=yourplot(x,y); %u dont want to interact with this
set(handlesfigure,'HitTest','off')

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

fjnb86
fjnb86 2011년 11월 15일
Data cursor has an option called Selection->"Snap to nearest data vertex" and it works well but only when you have one data represented.
If I plot more in the same figure this function catches both of them and I only want this for the scatter plot.
thanks!

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by