2012-02-17 89 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-th线width=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中)。