1
votes

How can i get the value of cursor position from datacursor? here's my code

filename = handles.loadDataName;
x=importdata(filename,' ',indexend);
fid = fopen(filename,'r');
A = textscan(fid,'%f%f','Delimiter',' ','headerLines',indexstart);
data = cat(2,A{:});
time = data(:,1);
c1 = data(:,2);
plot(handles.axes_grafik,time,c1)
grid on;
dcm = datacursormode(gcf);
datacursormode on;
set(dcm, 'updatefcn', @myfunction)


function output_txt = myfunction( ~,event_obj)
dataIndex = get(event_obj,'DataIndex');
pos = get(event_obj,'Position');
output_txt = {[ 'Time: ',num2str(pos(1),5)] .....,
    ['Amplitude: ',num2str(pos(2),5)]};

When i tried to modified function output_txt to get pos(1) and Pos(2) into global variable, i got an error on figure which says 'error in custom datatip string function'

I want to retrieve pos(1) and Pos(2) to display it in editbox. Is there any way to do this? Thanks

1
Did you run through your myfunction in debug mode and checked that it works? The "error message" usually is correct - something probably went wrong in myfunction... E.g. append a disp(output_txt); to it and check that the message you want really gets displayed... - sebastian

1 Answers

1
votes

[x,y] = ginput

this command will let u click on ur figure as many times as u want until you hit enter then return the xy coords.