2013-07-31 147 views
1

我想在Matlab中用不同的颜色绘制两个图。然后我想在右上角的一个框里面给两个图表分别命名。我写的代码是:在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') 

它产生所需的图形。然而在右上角,它绘制了一个红线线,用于耦合和非耦合。我反而想要红色加上和蓝色解开。任何解决方案

+3

它为我的作品:红线和蓝线的传说。只有他们被扭转。您可以尝试'传说('耦合','解耦','位置','东北部')' –

+0

右上角的框显示耦合和非耦合的不同颜色。它对我来说显示 – Adwaitvedant

+0

不同的颜色。我只是定义了一些随机的'x','err_t_coupled','err_t_uncoupled'并粘贴了你的代码。 –

回答

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') 
相关问题