在matlab上绘制不同颜色的多个图形

时间:2013-07-31 11:02:38

标签: matlab legend matlab-figure

我想在Matlab中绘制两个不同颜色的图形。然后我想在右上角有一个方框,用两个图表命名。我写的代码是:

x=1:1:max
%err_t_coupled,err_t_uncoupled are arrays
figure
plot(x, err_t_coupled,'red',x, err_t_uncoupled,'blue') 
legend('uncoupled','coupled','Location','Northeast') 
title('Maximum error') 
xlabel('Iterations') 
ylabel('Maximum error wrt D-Norm')

它生成所需的图形。但是在右上角,它为耦合和非耦合绘制了红色线。我反而希望红色用于耦合,而蓝色用于解耦。有解决方案吗

1 个答案:

答案 0 :(得分:3)

问题与err_t_couplederr_t_uncoupled是数组而不是向量这一事实有关。

这将有效:

x=1:1:max
%err_t_coupled,err_t_uncoupled are arrays
figure
h1 = plot(x, err_t_coupled,'red');
hold on
h2 = plot(x, err_t_uncoupled,'blue');
legend([h1(1) h2(1)], 'coupled','uncoupled','Location','Northeast') 
title('Maximum error') 
xlabel('Iterations') 
ylabel('Maximum error wrt D-Norm')
相关问题