在for循环中为gscatter图添加不同的颜色线图

时间:2015-07-17 11:02:13

标签: matlab plot

我有以下代码:

limits = [-1 1 -1 1];
g1 = [1;2;3;4;5;6;7;8];
col = [1 1 0; 1 0 1; 0 1 1; 1 0 0; 0 1 0; 0 0 1; 0 0 0; 0.5 0.3 0.1];
sym = 'vvvv^^^^';
sym2 = 'xxxxxxxx';
points = 30;

for i = 1:8;
    mhuR(i,1) = mean(HSRXdistpR(i,:));
    mhuR(i,2) = mean(HSRYdistpR(i,:));
    mhuL(i,1) = mean(HSRXdistpL(i,:));
    mhuL(i,2) = mean(HSRYdistpL(i,:));
    mhuX(i,1) = mean(TotxcomHSRpX(i,:));
    mhuX(i,2) = mean(TotxcomHSRpY(i,:));
    CR{i} = cov(HSRXdistpR(i,:),HSRYdistpR(i,:));
    CL{i} = cov(HSRXdistpL(i,:),HSRYdistpL(i,:));
    CX{i} = cov(TocomXdistp(i,:),TocomYdistp(i,:));
    ellipR{i} = uncertEllip(CR{i},mhuR(i,:),points);
    ellipL{i} = uncertEllip(CL{i},mhuL(i,:),points);
    ellipX{i} = uncertEllip(CX{i},mhuX(i,:),points);
end

figure; hold on
scatter(HSRXdistbR2,HSRYdistbR2,'ko'); hold on
scatter(HSRXdistbL2,HSRYdistbL2,'ko'); hold on
scatter(TocomXdistb2,TocomYdistb2,'kx'); hold on
gscatter(HSRXp2(:,1),HSRYp2(:,1),g1,col,sym), hold on
gscatter(HSRXp2(:,2),HSRYp2(:,2),g1,col,sym), hold on
gscatter(copHSRXp2(:,2),copHSRYp2(:,2),g1,col,sym2), hold on

for i = 1:8;
    plot(ellipR{i}(:,1),ellipR{i}(:,2),col(i,:)), hold on
    plot(ellipL{i}(:,1),ellipL{i}(:,2),col(i,:)), hold on
    plot(ellipX{i}(:,1),ellipX{i}(:,2),col(i,:)), hold on
end

vline(0)
hline(0)
legend('base','base','base','-0.04m', '-0.08m', '-0.12m', '-0.16m', '0.04m', '0.08m', '0.12m', '0.16m');
title({'xCoM and left and right foot placement relative',...
        'to xCoM per perturbation, for all subjects'})
axis(limits)
xlabel('x displacement (scaled)');
ylabel('y displacement (scaled)');`

我试图让线图(第二个for循环)与散点图数据具有相同的颜色(不确定性椭圆各自属于它们自己的散点)。但是,它不允许我使用col矩阵中的颜色。我在这里错过了什么吗?

错误:

  

数据必须是单个矩阵Y或X,Y列对。

不尝试定义颜色可以正常工作,但当然颜色不匹配。

1 个答案:

答案 0 :(得分:1)

尝试用以下方法替换每个错误行:

plot(ellipR{i}(:,1),ellipR{i}(:,2),'Color',col(i,:));