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)以在編輯框中顯示它。有沒有辦法做到這一點?由於
你是否在調試模式下運行你的'myfunction'並檢查它是否有效? 「錯誤信息」通常是正確的 - 在「myfunction」中可能出錯了......例如,追加一個'disp(output_txt);'給它並檢查你想要的信息是否真的顯示出來...... – sebastian