2012-02-17 83 views

回答

17

你可以處理所有線路上的電流圖形對象與FINDOBJ功能:

hline = findobj(gcf, 'type', 'line'); 

然後你就可以改變一些屬性對所有的線對象:

set(hline,'LineWidth',3) 

或只是其中的一些:

set(hline(1),'LineWidth',3) 
set(hline(2:3),'LineStyle',':') 
idx = [4 5]; 
set(hline(idx),'Marker','*') 
+0

非常感謝!這工作得很好! – aarelovich 2012-02-17 17:27:57

2

爲了操縱一個圖形對象,你需要訪問他們的句柄。如果使用繪圖函數創建圖形,這些將返回句柄給你。當你打開一個人物,因爲是你的情況,你需要遵循一個圖形對象樹查找句柄要處理的特定元素。

This page具有大約圖形對象的結構信息。

到要取決於你的身材手柄的路徑,但是,作爲一個例子,如果你的身材是用一個簡單的plot命令創建的,這將是改變線路屬性的一種方法:

x = 0:0.1:2; 
plot(x,sin(x)); 

fig = gcf % get a handle to the current figure 
% get handles to the children of that figure: the axes in this case 
ax = get(fig,'children') 
% get handles to the elements in the axes: a single line plot here 
h = get(ax,'children') 
% manipulate desired properties of the line, e.g. line width 
set(h,'LineWidth',3) 
+0

感謝您的信息。我會考慮。不過,我發現上面的替代方案更直觀。 – aarelovich 2012-02-17 17:28:27

2

除了@yuk答案,如果你有一個傳說繪製以及

hline = findobj(gcf, 'type', 'line'); 

將返回N x 3線(或更確切地說 - lines plotted + 2x lines in legend)。 我會在這裏的情況下,只有當看所有正在繪製的線條也都在傳說。

測序是怪異: 中的5條線(讓我們注意到他們1 to 5)繪製和傳奇加入,你將有

hline: 
1 : 5 th line (mistical)  
2 : 5 th line (in legend) 
3 : 4 th line (mistical)  
4 : 4 th line (in legend) 
5 : 3 th line (mistical)  
6 : 3 th line (in legend) 
7 : 2 th line (mistical)  
8 : 2 th line (in legend) 
9 : 1 th line (mistical)  
10: 1 th line (in legend) 
11: 5 th line (in plot) 
12: 4 th line (in plot) 
13: 3 th line (in plot) 
14: 2 th line (in plot) 
15: 1 th line (in plot) 

作爲一個解決方案(星期五晚上拖延)我做了這個情況小寶寶:

解決方案1:,如果你不想要重置傳說

檢測,如果有一個傳說,多少林ES繪製:

hline = findobj(gcf, 'type', 'line'); 
isThereLegend=(~isempty(findobj(gcf,'Type','axes','Tag','legend'))) 

if(isThereLegend) 
    nLines=length(hline)/3 
else 
    nLines=length(hline) 
end 

對於每一行找到合適的把手和該行(這也將適用於相應的圖例線)做的東西

for iterLine=1:nLines 
    mInd=nLines-iterLine+1 
    if(isThereLegend) 
     set(hline([(mInd*2-1) (mInd*2) (2*nLines+mInd)]),'LineWidth',iterLine) 
    else 
    set(hline(mInd),'LineWidth',iterLine)  
    end 
end 

這使得與每個i-thwidth=i,在這裏您可以添加自動屬性更改;

解決方案2:保持簡單

擺脫傳說,走線的照顧,復位傳奇。

legend off 
hline = findobj(gcf, 'type', 'line'); 
nLines=length(hline) 

for iterLine=1:nLines 
    mInd=nLines-iterLine+1 
    set(hline(mInd),'LineWidth',iterLine)  
end 
legend show 

這可能不適合的情況下,當傳說中必須被放置在一些地方speciffic等

0

您可以在觀衆也行只是點擊右鍵,並更改屬性那裏。這也改變了相應的「圖例」條目(至少在2014b中)。