天天看點

MATLAB 設定 資料遊标的精度

1、建立一個名稱為NewCallback.m的M檔案,代碼如下:

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),5)],...
% 此處的pos(1)後的數字,即X軸的資料遊标的顯示精度位數
['Y: ',num2str(pos(2),5)]};
% 此處的pos(2)後的數字,即Y軸的資料遊标的顯示精度位數

% 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),5)];
% 此處的pos(3)後的數字,即Z軸的資料遊标的顯示精度位數
end
           

2、将該檔案儲存在MATLAB的目前檔案夾目錄下

3、輸入畫圖代碼,并在figure下輸入以下代碼:

dcm_obj = datacursormode(gcf);
set(dcm_obj,'UpdateFcn',@NewCallback)
           

繼續閱讀