SCILAB 在循环生成的图中添加图例

SCILAB Adding legend in a plot generated by a loop

我想知道如何在 SciLab 循环生成的图中添加图例。有 4 个循环,每个循环都有不同的图例(和颜色)。

我尝试了下面的代码。但是,给了我 4 个颜色相同的图例(在红色的情况下)。

inta=read("H_intacta_num.txt",-1,1500)
d1=read("H_dano1_num.txt",-1,1500)
d2=read("H_dano2_num.txt",-1,1500)
d3=read("H_dano3_num.txt",-1,1500)
leia1=read("Dados_MagN1.txt",-1,3);
frequ=leia1(:,1)

\loop1 - red (label: healthy)
for i=48:94
    plot(frequ,inta(i,:),'r')
end

\loop 2 - blue (label: Damaged_L1)
for j=48:94
    plot(frequ,d1(j,:),'b')
end

\loop 3 - black (label: Damaged_L2)
for j=37:72
    plot(frequ,d2(j,:),'k')
end

\loop 4 - ciano (label: Damaged_L3)
for j=36:70
    plot(frequ,d3(j,:),'c')
end

ylabel("Amplitude (m/s^2)/N")
xlabel("Frequency (Hz)")
p=legend(['Healthy';'Damaged_L1';'Damaged_L2';'Damaged_L3'],[2])

这里 legend 将考虑堆栈中的前 4 条折线,因此是红色的。您可以通过这种方式更改链接(顺便说一下,行注释是 // 而不是 \

//loop1 - red (label: healthy)
for i=48:94
    plot(frequ,inta(i,:),'r')
end
h(1)=gce()

//loop 2 - blue (label: Damaged_L1)
for j=48:94
    plot(frequ,d1(j,:),'b')
end
h(2)=gce()

//loop 3 - black (label: Damaged_L2)
for j=37:72
    plot(frequ,d2(j,:),'k')
end
h(3)=gce()

//loop 4 - ciano (label: Damaged_L3)
for j=36:70
    plot(frequ,d3(j,:),'c')
end
h(4)=gce()

ylabel("Amplitude (m/s^2)/N")
xlabel("Frequency (Hz)")
p=legend(h, ['Healthy';'Damaged_L1';'Damaged_L2';'Damaged_L3'],[2])