如何给不同颜色的Matlab图形命名

How to give titles to the different colours of Matlab graphs

这部分代码,将在一帧中创建三个不同的图形,并且它们都将具有不同的颜色。但是不知道哪个颜色对应哪个i.

figure('Name','function','NumberTitle','on')
hold all

for i = 1:N 
    plot(input_firingRate(i,:),output_firingRate(i,:))
    ax = gca;
    ax.XAxisLocation = 'origin';
    ax.YAxisLocation = 'origin';       
end

有没有什么方法可以在框架内使用 title-like 方法来区分不同的结果和颜色?例如:

Test i = 1 : 'r'
Test i = 2 : 'g'
Test i = 3 : 'b'

这就是图例函数。 doc page 上有一些很好的例子。

您可以将每个绘图的标签写入元胞数组,然后在循环后将元胞数组传递给对 legend 的单个调用:

N = 3;
figure('Name','function','NumberTitle','on')
hold all
titles = cell(N,1);
for i = 1:N 
    plot(1:100,randn(1,100))
    titles{i} = ['line ', num2str(i)];
end
legend(titles);