2013-12-16 37 views
1

如何从数据光标获取光标位置的值?这里是我的代码如何从GUI中的数据光标获取值

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)]}; 

当我试图修改function output_txt拿到POS(1)和POS(2)为全局变量,我得到的图它说“错误的自定义提示字符串函数”

错误

我想检索pos(1)和Pos(2)以在编辑框中显示它。有没有办法做到这一点?由于

+0

你是否在调试模式下运行你的'myfunction'并检查它是否有效? “错误信息”通常是正确的 - 在“myfunction”中可能出错了......例如,追加一个'disp(output_txt);'给它并检查你想要的信息是否真的显示出来...... – sebastian

回答

1

[x,y] = ginput

这个命令将让ü乌尔图多次点击为u想,直到你按下回车键,然后返回XY COORDS。