我的matlab图中需要不同的颜色

时间:2013-07-04 14:58:57

标签: matlab plot

这是我的情节代码。问题是我的情节中的两条线具有相同的颜色,我需要一条特殊的线条中的每一条线(总共4条线)。

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 

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

2 个答案:

答案 0 :(得分: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],:);

并且,我认为你不需要在第一个循环中使用它。

答案 1 :(得分:0)

使用HSV获得不同的颜色:

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