2013-07-04 35 views
0

这是我的剧情代码。问题是我的情节中的两条线具有相同的颜色,我需要一个特殊的情节(共4行)。我需要不同的颜色在我的matlab阴谋

for i=1:nFolderContents; 
    [~, data] = hdrload(folderContents(i,:)); 
    if size(folderContents(i,:),2)<size(folderContents,2); 
     temp=folderContents(i,6:9); 
    else 
     temp=folderContents(i,6:7); 
    end 
    temp1(i)=strread(temp); 
    w=2*pi*(data([35 51 68 101],1)); 
    permfreespace=8.854e-12; 
    perm=data([36 52 69 101],3); 
    cond=perm.*w.*permfreespace; 
    conds([36 52 69 101],i)=cond; 
    hold on 

end 


figure(4);plot(temp1,conds); 
gcf=figure(4); 
set(gcf,'Position', [0 0 295 245]); 
xlabel('Temperature [\circC]'), ylabel ('Conductivity [s/m]'); 
title('Different frequencies'); 
legend('1.02 GHz','1.50 GHz','2.01 GHz','3 GHz'); 
axis([20 52 0 4]); 
box on 

新代码:

conds=zeros(101,28); 
for i=1:nFolderContents; 
    [~, data] = hdrload(folderContents(i,:)); 
    if size(folderContents(i,:),2)<size(folderContents,2); 
     temp=folderContents(i,6:9); 
    else 
    temp=folderContents(i,6:7); 
    end 
    temp1(i)=strread(temp); 
    w=2*pi*(data([35 51 68 101],1)); 
    permfreespace=8.854e-12; 
    perm=data([36 52 69 101],3); 
    cond=perm.*w.*permfreespace; 
    conds([36 52 69 101],i)=cond; 
    hold all 

end 
diff = hsv(101); 
for i=1:101 
    figure(4),plot(temp1(1,:),conds(i,:),'color',diff(i,:)); 
    hold all; 
end 
gcf=figure(4); 
set(gcf,'Position', [0 0 295 245]); 
xlabel('Temperature [\circC]'), ylabel ('Conductivity [s/m]'); 
title('Different frequencies'); 
legend('1.02 GHz','1.50 GHz','2.01 GHz','3 GHz'); 
axis([20 52 0 4]); 
box on 

的问题是,我在图例框获得相同的颜色了。

+0

使用'hold all'而不是'hold'# – Dan

+0

仍然存在同样的问题 – yaya

+0

'temp1'和'conds'的尺寸是多少? – Dan

回答

1

您与101线(零)中定义的变量conds,则改为4线到某些值。现在你只想绘制这4行,但你的循环运行了101次,所以它也绘制了零线。这就是你得到一条零线的原因(实际上97条线......)。这也是你为4条曲线获得相同颜色的原因,可能是各种图形颜色,在零线上“浪费”。

您应该运行循环只有4次,使用

rows=[36 52 69 101] ; 
color='rgbc' 
for i=1:4 
    plot (temp(1,:), cond(rows(i),:), 'color',color(i)); 
    hold on 
end 
hold off 

其实,你并不需要这个conds=zeros(101,28)所有,只是纠正插入值conds到行:

conds=cond([36 52 69 101],:); 

而且,我不认为你需要它在第一个循环内。

+0

嗨,谢谢你的帮助,但是我得到了这个错误的评论???索引超出了矩阵的尺寸 Error in == (4); plot(temp(1,:),cond(rows(i),:),'color',color(i)); – yaya

0

使用HSV以获得不同的颜色:

diff = hsv(101); 
for i=1:101 
    plot(temp1(1,:),conds(i,:), 'color',diff(i,:)); 
    hold on; 
end 
+0

嗨,感谢您的帮助。但仍然获得红色两次 – yaya

+0

@yaya他们必须是不同的红色阴影。我们的眼睛不能区分它们。 :) –

+0

@yaya尝试使用全部在这里而不是等待。看看ColorOrder http://www.mathworks.in/help/matlab/ref/axes_props.html?s_tid=doc_12b –