MATLAB Answers

0

Data cursor in MATLAB

Asked by Marat Zhe on 18 Jan 2016
Latest activity Edited by TARAM
on 1 Feb 2016
Hi MathWorks staff and Matlab users. I work on Matlab 2013a software. Main file is "question.m". I have problem with Data cursors.
When i place data cursor on contourf plot i see both 2 coordinates and amplitude level (i. e. z-value ) of the point and everything is OK (see image "1"). But when i save Text Update Function (press "Edit Text Update Function", go to file- save as - "NewCallback.m") to my working directory and then try to open it (press "Select Text Update Function" and choose this new file "NewCallback.m" ) i earn only 2 numbers instead of 3 !!?? I earn only coordinates, but not amplitude.
Look at image "2__I selected text update function.png".
Question: How can i obtain all 3 coordinates of point using "NewCallback.m" (or another modified text update function)?
Thanks in advance!!

  1 Comment

TARAM
on 25 Jan 2016
Hello dear Matlab users and staff! As far as my licence allows to install newer version of Matlab, i decided to install Matlab 2014a and check, if this problem appears in it. Unfortunately problem is still here...
My system administrator told, that it will be hard to install 2015 version (but, as far as i understand, my current licence supports it).
Nevertheless, may be there is way to go through this problem?
Thanks in advance!!!
PS: I am Marat Zhe . This is my new account. I created it, because licence deassociated with my old account . I tried to add it, but error appeared...

Sign in to comment.

1 Answer

TARAM
Answer by TARAM
on 27 Jan 2016
Edited by TARAM
on 1 Feb 2016
 Accepted Answer

Hello everybody. I think, i've overcomed this problem. Answer on this page
helped me very much. I modified code i've found there.
After contourfplot i write
datacursormode on;
dcm_obj = datacursormode(gcf);
set(dcm_obj,'DisplayStyle','datatip',...
'UpdateFcn',@myfunction);
My text update function is
function output_txt = myfunction(obj,event_obj)
global d_theta d_phi; %Theta and phi angle steps
% 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');
val_X=pos(1);
val_Y=pos(2);
h=get(event_obj,'Target');
% We can go other, more time consuming way
% X=get(h,'XData');
% Y=get(h,'YData');
% [i_1,i_2]=find((X==val_X) & (Y==val_Y)).
% But i can find locations of the array elements
%more easily, as far as i made it by myself
%~~~~~~ Polar coordinate Theta ~~~~~~
Theta_angle=sqrt(val_X^2+val_Y^2);% in degrees !!!
%~~~~~~ Polar coordinate Theta ~~~~~~
i_1=Theta_angle/d_theta+1;
i_1=round(i_1);%
%~~~~~~ Polar coordinate Phi ~~~~~~
Phi_angle=atan(val_Y/val_X);
if (val_X<0)&&(val_Y>=0)
Phi_angle=pi+Phi_angle;
elseif (val_X<0)&&(val_Y<0)
Phi_angle=pi+Phi_angle;
elseif (val_X>=0)&&(val_Y<0)
Phi_angle=2*pi+Phi_angle;
end
Phi_angle=Phi_angle*180/pi; % transform to degrees
Phi_angle=round(Phi_angle*10)/10;%i need 1 decimal
%~~~~~~ Polar coordinates Phi~~~~~~
i_2=Phi_angle/d_phi+1;
i_2=round(i_2);
Z=get(h,'ZData');% read big array everytime i move datatip????
Level=Z(i_1,i_2);
output_txt = {[ 'Phi, deg= ',num2str(Phi_angle,'%.1f')],...
[ 'Theta, deg= ',num2str(Theta_angle,'%.1f')],...
[ 'Level, dB= ',num2str(Level,'%.2f')]};
end
To view result open sticked file "result.png". I tried to stick data file "data_exhample_" (about 1 MB) to this message, but i can't. Error appears...
P.S.: After my attempts to attach 2 pictures to my message (I wanted to attach 2 pictures, but only one picture displayed correctly,) i was deprived of ability to attach files. I think, that my problems are because of old browser. There is limitation on this site: i can attach no more than 10 pictures in 24 hours.
P.S.2: I accepted this my answer by my old user account Marat Zhe :P
P.S.3: I finally attached 1 more image and data file..
Image 1
Image 2

  0 Comments

Sign in to comment.