2016-03-06 89 views
0

我正在繪製我設計的陷波濾波器的幅度和相位響應,我需要標記截止頻率以及陷波頻率點。如果您點擊一個圖表,我想顯示相同的信息。有沒有一種方法可以強制MATLAB顯示如果單擊某個點時出現的那些框?在MATLAB中添加特定點信息

我附上了一張圖片,顯示我的意思。我想在我選擇的特定頻率點上得到類似這樣的盒子。 enter image description here

回答

0

這實際上可以使用數據光標的某些未公開的特徵(info)更可靠一些地進行。首先,我們將獲得圖形的底層datacursormode,然後使用它來添加和移動數據提示(如圖中的數據提示)。

fig = figure(); 

% Plot some fake data for now 
xdata = linspace(0, 2*pi, 100); 
ydata = sin(xdata); 

hLine = plot(xdata, ydata); 

% Get the datacursormode of the current figure and enable it 
cursorMode = datacursormode(gcf); 
set(cursorMode, 'enable','on') 

現在我們有datacursormode對象,我們可以用它來添加一些新的數據提示。

datatip = cursorMode.createDatatip(handle(hLine)); 
% X,Y position at which to place the datatip 
set(datatip, 'Position', [xdata(50), ydata(50)]); 

enter image description here

如果我們希望我們可以再次提出這個數據提示。

set(datatip, 'Position', [xdata(1), ydata(1)]); 

的非常好的事情,是使用cursorMode對象,我們還可以創建數據提示

datatip2 = cursorMode.createDatatip(handle(hLine)); 
set(datatip2, 'Position', [xdata(75), ydata(75)]) 

enter image description here

通過將這些信息與自己的情節和數據相結合,您應該能夠自動放置您需要的數據提示。

1

下面一個例子,我建爲一個指數函數:

clear all 

figure 
f = plot(exp(1:10)); 

datacursormode on 

% get the handle of the data cursor 
hdc = get(gcf,'WindowButtonDownFcn'); 
dcm = hdc{3}{2}; 


props.Position = [min(exp(1:10)) log(min(f)) 1]; 

dcm.createDatatip(f,props); 

但是你必須概括coordiates的定義光標到您的案件。