2013-08-07 26 views
1

我繪製了數據點,並在Matlab中使用'fit'擬合了它們之間的指數曲線。問題在於,通過擬合函數,我得到了我想要繪製的擬合線,但是在我的常規標記上還有額外的標記。我通過將想要的標記繪製在不需要的頂部來解決這個問題,以至於看不到它們。現在解決問題。當我想展示這些傳說時,這些點也在那裏。如何刪除圖例中的標記而不刪除已安裝的線條,因爲它們都隱藏在擬合函數中?我可以通過繪製不需要的標記來停止「適合」嗎?所以,我想在下面的圖片中刪除名爲'hoff'的藍點。當你還使用Fit時刪除圖例中的對象,Matlab

enter image description here

回答

2

您可以通過手動留出線條的手柄,你不想成爲傳說離開了傳奇條目。試試這個:

%if you plot something, that you want showing up in the legend, save its handle: 
h_line = plot(x,y) 
%you dont want to show up this line? dont do anything, just plot it: 
plot(myMarker) 
%then set the legend-> you can add the text for your legend-entries with 
%a cell-array containing the strings you want to show up: 
legend([h_line another_line],{'Text1' 'Text2'}) 

與例子(見註釋),我來到了這個解決方案:

close all 
X=[1:10]; 
Y=X*0.5+0.1; 
ft = fittype('poly2'); 
f = fit(X', Y',ft); 
ha=plot(f) 
hold on 
hc=plot(X,Y) 
hb=errorbar(X, Y, X*0.1, 'squarek','MarkerFaceColor','k','markersize',5) 
hleg1 = legend([ha hc],{'hnh','ghg'}); 

- >這只是折中一下劇情命令。希望可以幫助...

的結果應該是這樣的:

enter image description here

+0

我已經試過了。問題是,當我繪製出適合的線時,我同時得到紅線和藍點。我想在我的陰謀裏有黑色標記和紅線。如果我想命名給出適合線的情節,那麼藍點也將在那裏。 – Djamillah

+0

你能顯示劇情指令嗎?那麼我可以重現它... –

+0

%生成擬合線: ft = fittype('exp1'); f = fit(X',Y',ft); 情節(F,X,Y) errorbar(X,Y,錯誤 'squarek', 'MarkerFaceColor', 'K', 'markersize',5) hleg1 =圖例( '霍夫', 'HNH' , '溫室氣體'); – Djamillah

相關問題