2015-08-15 118 views
0

我想绘制错误信号。当错误为零时,绘图应为黑色。每当出现错误时,它应该是红色的。我在数组excdIdx中捕获错误的索引。 我的目标是绘制红色和非黑色误差指数的误差指数。出于某种原因,for循环无法正常工作。使用matlab绘制不同颜色的选定索引

ErrAxis是轴 excdIdx包含索引的表要绘制内部重定向

h(8) = subplot(plotCount,1,ErrAxis); 
    hold off; 
    if excdIdx > 0 

     plot(time(1:excdIdx),Output(1:excdIdx) - trueSignal(1:excdIdx),'k-'); hold on; 

     %this method to plot the error indices in red is not working 
     % for elem = 1: size(excdIdx, 2) 
     %  index_1 = excdIdx(elem); 
     %  index_2 = excdIdx(elem+1); 
     %  plot(time(index_1:index_1+1),Output(index_1:index_1+1) - trueSignal(index_1:index_1+1),'r-'); hold on; 
     % end 

    else 
     plot(time,Output - trueSignal,'k-'); hold on; 
    end 
+1

您可以创建一个[MCVE](http://stackoverflow.com/help/mcve)。 – Matt

回答

0

如果用户要打印单个数据点,我认为你应该使用scatter。请尝试以下代码:

h(8) = subplot(plotCount,1,ErrAxis); 
hold off; 
if excdIdx > 0 
    scatter(time(1:excdIdx),Output(1:excdIdx) - trueSignal(1:excdIdx),'markerfacecolor','k'); hold on; 
    for elem = 1: size(excdIdx, 2) 
     index_1 = excdIdx(elem); 
     index_2 = excdIdx(elem+1); 
     scatter(time(index_1:index_1+1),Output(index_1:index_1+1) - trueSignal(index_1:index_1+1),'markerfacecolor','r'); 
    end 
else 
    scatter(time,Output - trueSignal,'markerfacecolor','k'); hold on; 
end